]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/closure-in-projection-issue-97405.rs
Rollup merge of #105837 - compiler-errors:issue-105728, r=estebank
[rust.git] / src / test / ui / regions / closure-in-projection-issue-97405.rs
1 // Regression test for #97405.
2 // In `good_generic_fn` the param `T` ends up in the substs of closures/generators,
3 // but we should be able to prove `<Gen<T> as Iterator>::Item: 'static` without
4 // requiring `T: 'static`
5
6 // edition:2018
7 // check-fail
8
9 fn opaque<F>(_: F) -> impl Iterator { b"".iter() }
10
11 fn assert_static<T: 'static>(_: T) {}
12
13 fn good_generic_fn<T>() {
14     // Previously, proving `<OpaqueTy<type_of(async {})> as Iterator>::Item: 'static`
15     // used to require `T: 'static`.
16     assert_static(opaque(async {}).next());
17     assert_static(opaque(|| {}).next());
18     assert_static(opaque(opaque(async {}).next()).next());
19 }
20
21
22 // This should fail because `T` ends up in the upvars of the closure.
23 fn bad_generic_fn<T: Copy>(t: T) {
24     assert_static(opaque(async move { t; }).next());
25     //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
26     assert_static(opaque(move || { t; }).next());
27     //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
28     assert_static(opaque(opaque(async move { t; }).next()).next());
29     //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
30 }
31
32 fn main() {}