Skip to content
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

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

Closed
compiler-errors opened this issue Dec 14, 2023 · 3 comments · Fixed by rust-lang/rust#119091
Closed

Comments

@compiler-errors
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 19, 2023
…ural-normalize, r=lcnr

Use alias-eq in structural normalization

We don't need to register repeated normalizes-to goals in a loop in structural normalize, but instead we can piggyback on the fact that alias-eq will already normalize aliases until they are rigid.

This fixes rust-lang/trait-system-refactor-initiative#78.

r? lcnr
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 19, 2023
Rollup merge of rust-lang#119091 - compiler-errors:alias-eq-in-structural-normalize, r=lcnr

Use alias-eq in structural normalization

We don't need to register repeated normalizes-to goals in a loop in structural normalize, but instead we can piggyback on the fact that alias-eq will already normalize aliases until they are rigid.

This fixes rust-lang/trait-system-refactor-initiative#78.

r? lcnr
@compiler-errors
Copy link
Member Author

This got fixed ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant