Skip to content

defining type-alias-impl-trait inside closures is broken #105498

Closed
@aliemjay

Description

@aliemjay

All these test cases should pass:

#![feature(type_alias_impl_trait)]
trait Cap<'a> {}
impl<T> Cap<'_> for T {}

mod case1 {
    type MyStr<'x> = impl Sized + super::Cap<'x>;
    fn case1<'s>(s: &'s str) {
        || { let _: MyStr<'s> = s; };
        //~^ ERROR unconstrained opaque type
    }
}

mod case2 {
    type MyStr<'x> = impl Sized + super::Cap<'x> + 'x; // note `+ 'x`
    fn case2<'s>() {
        let _: MyStr<'s> = "";  // inferred ty: &'s str
        || -> MyStr<'s> { "" }; // inferred ty: &'static str
        //~^ ERROR concrete type differs from previous defining opaque type use
    }
}

mod case3 {
    type MyStr<'x> = impl Sized + super::Cap<'x>;
    fn case3<'s>() {
        |s: &'s str| { let _: MyStr<'s> = s; };
        //~^ ERROR captures lifetime that does not appear in bounds
    }
}

The current algorithm for member constraints is broken when used in closures because it assumes the relations between universal regions to be known, which is not true when we're borrow-checking closures.

@rustbot label C-bug T-types F-type_alias_impl_trait A-borrow-checker

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-typesRelevant to the types 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