Skip to content

Outlives bounds for projections are broken when used with generators/closures #97405

Closed
@aliemjay

Description

@aliemjay

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:

_ => self.recursive_bound(ty.into(), visited),

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

Metadata

Metadata

Assignees

Labels

A-closuresArea: Closures (`|…| { … }`)A-coroutinesArea: CoroutinesA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions