Skip to content

Broken MIR: relate_type_and_user_type may receive unnormalized types #141708

Closed
@compiler-errors

Description

@compiler-errors

This code ICEs:

trait Foo<'a> {
    type Assoc;
}

impl<T> Foo<'_> for T {
    type Assoc = T;
}

fn foo<'b: 'b, T: for<'a> Foo<'a>, F: for<'a> Fn(<T as Foo<'a>>::Assoc)>(_: F) -> (T, F) {
    todo!()
}

fn main() {
    let (x, c): (i32, _) = foo::<'static, _, _>(|_| {});
}

We create a very sneaky closure type that has the signature of for<'a> fn(<i32 as Foo<'a>>::Assoc). Note that this type is not normalized, because of higher-ranked normalization problems w/ the old trait solver.

We then store this type into c in the let statement, and because it's a pattern, we end up storing a user type annotation that links it to the field ascription. Since it's a pattern with a single field place elem, we end up normalizing the closure type here:

self.structurally_resolve(ty, locations)

note that this is a full normalization in the old solver.

We then try to relate the unnormalized and normalized closure signatures, which fails in the old solver.

Metadata

Metadata

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions