diff --git a/src/doc/rustc-dev-guide/src/solve/candidate-preference.md b/src/doc/rustc-dev-guide/src/solve/candidate-preference.md index 461523424b3c..22ec3162b73f 100644 --- a/src/doc/rustc-dev-guide/src/solve/candidate-preference.md +++ b/src/doc/rustc-dev-guide/src/solve/candidate-preference.md @@ -454,6 +454,30 @@ where } ``` +#### Trait definition cannot use associated types from always applicable impls + +The `T: Trait` assumption in the trait definition prevents it from normalizing +`::Assoc` to `T` by using the blanket impl. This feels like a somewhat +desirable constraint, if not incredibly so. + +```rust +trait Eq {} +impl Eq for T {} +struct IsEqual, U>(T, U); + +trait Trait: Sized { + type Assoc; + fn foo() -> IsEqual { + //~^ ERROR the trait bound `Self: Eq<::Assoc>` is not satisfied + todo!() + } +} + +impl Trait for T { + type Assoc = T; +} +``` + [`Candidate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_next_trait_solver/solve/assembly/struct.Candidate.html [`CandidateSource`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_next_trait_solver/solve/enum.CandidateSource.html [`fn merge_trait_candidates`]: https://github.com/rust-lang/rust/blob/e3ee7f7aea5b45af3b42b5e4713da43876a65ac9/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs#L1342-L1424