Skip to content

closures/async blocks capture all lifetimes in scope #100372

New issue

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

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

Already on GitHub? # to your account

Open
aliemjay opened this issue Aug 10, 2022 · 4 comments
Open

closures/async blocks capture all lifetimes in scope #100372

aliemjay opened this issue Aug 10, 2022 · 4 comments
Labels
A-closures Area: Closures (`|…| { … }`) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented Aug 10, 2022

This should compile, but it fails with a cryptic error message:

#![feature(type_alias_impl_trait)]

trait Trait {}

type Fut = impl Sized;

fn call<'a>() -> Fut
where
    &'a (): Trait,
{
    async {}
    //~^ ERROR the trait bound `&'<empty> (): Trait` is not satisfied
}

The reason for this is that the hidden type of Fut in the defining function is call::<'a>::generator#0, but because we can't reference 'a in the hidden type, the type is converted to call::<'empty>::generator#0 here:

.unwrap_or(infcx.tcx.lifetimes.re_root_empty),

The hidden type then fails WF checks because of the additional checks done in #96899 and #97183.

This now affects only type-alias-impl-trait, only because we don't WF-check the hidden type of return-position-impl-trait after borrow-checking.

@rustbot label A-impl-trait A-closures F-type_alias_impl_trait C-bug T-compiler T-types

@rustbot rustbot added A-closures Area: Closures (`|…| { … }`) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Aug 10, 2022
@aliemjay aliemjay changed the title closures/async blocks capture all lifetime generics in scope closures/async blocks capture all lifetimes in scope Aug 10, 2022
@jackh726
Copy link
Member

Is this just a duplicate of #100267?

@aliemjay
Copy link
Member Author

aliemjay commented Aug 10, 2022

Oh, I should've made it more clear. They're indeed closely related. #100267 is a regression that I wanted to close so I opened this ticket to track other subtle manifestations of the same underlying bug that are not really regressions of #98835.

@jackh726
Copy link
Member

So, same bug different test case?

@aliemjay
Copy link
Member Author

This issue tracks a pre-existing problem: Opaque types inference expects the closure_substs.parent_substs to be free region variables independent of the the parent function. This why #98835 caused a regression in opaque types, it breaks this invariant. But this is already a buggy behavior as demonstrated by the above example and I think we can do better (maybe #92617 can help!)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
Status: Can do after stabilization
Development

No branches or pull requests

3 participants