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`
9 fn opaque<F>(_: F) -> impl Iterator { b"".iter() }
11 fn assert_static<T: 'static>(_: T) {}
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());
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