Skip to content

error promoting type-tests from closures #108635

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 Mar 2, 2023 · 0 comments · Fixed by #108691
Closed

error promoting type-tests from closures #108635

aliemjay opened this issue Mar 2, 2023 · 0 comments · Fixed by #108691
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. NLL-complete Working towards the "valid code works" goal T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented Mar 2, 2023

The following should pass borrowck:

trait Trait {
    type Item<'a>: 'a;
}

fn assert_static<T: 'static>(_: T) {}

fn test_args<I: Trait>() {
    let closure = |a, _b| assert_static(a);
    //~^ ERROR the associated type may not live long enough

    closure(None::<I::Item::<'_>>, &None::<I::Item::<'_>>);
}

fn test_upvars<I: Trait>() {
    let upvars = (None::<I::Item::<'_>>, &None::<I::Item::<'_>>);
    let _closure = || {
        let (a, _b) = upvars;
        assert_static(a);
        //~^ ERROR the associated type may not live long enough
    };
}

When promoting the type-test I::Item::<'_>: 'static from the closure to the parent function, we fail to do so because we can't express '_ in terms of universal regions because the corresponding free region doesn't have an external_name?:

self.definitions[upper_bound].external_name.unwrap_or(r)

@rustbot label C-bug T-types A-NLL NLL-complete A-borrow-checker

@rustbot rustbot added A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. NLL-complete Working towards the "valid code works" goal T-types Relevant to the types team, which will review and decide on the PR/issue. labels Mar 2, 2023
@bors bors closed this as completed in 8824994 Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. NLL-complete Working towards the "valid code works" goal T-types Relevant to the types 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