Closed
Description
I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=776e25cac316cad8c1ee83508ceb7f69
fn opaque<F>(_: F) -> impl Iterator { b"".iter() }
fn assert_static<T: 'static>(_: T) {}
fn generic_fn<T>() {
// proving `<OpaqueTy<type_of(async {})> as Iterator>::Item: 'static`
// somehow requires `T: 'static`.
assert_static(opaque(async {}).next());
//~^ the associated type `<impl Iterator as Iterator>::Item` may not live long enough
assert_static(opaque(|| {}).next());
//~^ the associated type `<impl Iterator as Iterator>::Item` may not live long enough
}
Both asserts don't pass. Adding <T: 'static>
bound on generic_fn
makes it compile.
We are requiring all the Substs
for closures and generators to outlive 'static
here:
This is wrong and inconsistent with the logic in fn compute_components<'tcx>(
Meta
Build using the Nightly version: 1.63.0-nightly
(2022-05-24 76761db)
Backtrace
<backtrace>
@rustbot label T-compiler A-lifetimes A-closures A-generators
@rustbot claim