Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aliemjay opened this issue May 25, 2022 · 1 comment · Fixed by #97406
Closed

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

aliemjay opened this issue May 25, 2022 · 1 comment · Fixed by #97406
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) A-coroutines Area: Coroutines A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented May 25, 2022

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

@aliemjay aliemjay added the C-bug Category: This is a bug. label May 25, 2022
@rustbot
Copy link
Collaborator

rustbot commented May 25, 2022

Error: Parsing assign command in comment failed: ...'bot assign' | error: specify user to assign to at >| ''...

Please let @rust-lang/release know if you're having trouble with this bot.

@rustbot rustbot added A-closures Area: Closures (`|…| { … }`) A-coroutines Area: Coroutines A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2022
@bors bors closed this as completed in b90a0ed Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-coroutines Area: Coroutines A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants