rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
21 stars 0 forks source link

Structural normalization tries to normalize (later) rigid aliases #78

Closed compiler-errors closed 8 months ago

compiler-errors commented 9 months ago
trait Trait {
    type Assoc;
}

fn call<T: Trait>(_: <T as Trait>::Assoc, _: T) { }

fn foo<T: Trait>(rigid: <T as Trait>::Assoc, t: T) {
    call::<_ /* ?0 */>(rigid, t);
    //~^ ERROR: type mismatch resolving `<T as Trait>::Assoc normalizes-to <T as Trait>::Assoc`
    //
    // Checking the first argument of `call` will cause us to
    // try to coerce `<?0 as Trait>::Assoc` and `<T as Trait>::Assoc`.
    // The left hand side is eagerly structurally normalized to
    // `?1`, then we add `<?0 as Trait>::Assoc normalizes-to ?1`,
    // which fails.
}

Given some <?0 as Trait>::Assoc, structural normalize currently checks if the predicate <?0 as Trait>::Assoc normalizes-to ?1 may hold. This is ambiguous, but fails later if ?0 is constrained to some T where T: Trait, because <T as Trait>::Assoc is now rigid.

compiler-errors commented 9 months ago

Maybe we should actually register a projection predicate in structural-normalize, but then break the loop if we end up resolving the same alias we get out.

This should also make sure we don't overflow in cases like T: Trait<Assoc = <T as Trait>::Assoc>??

compiler-errors commented 9 months ago

This (among other issues) is causing rustc to fail to compile syn.

compiler-errors commented 8 months ago

This got fixed ❤️