Skip to content

Commit 5f32528

Browse files
authored
Merge pull request #2797 from lcnr/main
add another candidate preference reason
2 parents f6cc6f6 + c48c591 commit 5f32528

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/solve/candidate-preference.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,30 @@ where
454454
}
455455
```
456456

457+
#### Trait definition cannot use associated types from always applicable impls
458+
459+
The `T: Trait` assumption in the trait definition prevents it from normalizing
460+
`<Self as Trait>::Assoc` to `T` by using the blanket impl. This feels like a somewhat
461+
desirable constraint, if not incredibly so.
462+
463+
```rust
464+
trait Eq<T> {}
465+
impl<T> Eq<T> for T {}
466+
struct IsEqual<T: Eq<U>, U>(T, U);
467+
468+
trait Trait: Sized {
469+
type Assoc;
470+
fn foo() -> IsEqual<Self, Self::Assoc> {
471+
//~^ ERROR the trait bound `Self: Eq<<Self as Trait>::Assoc>` is not satisfied
472+
todo!()
473+
}
474+
}
475+
476+
impl<T> Trait for T {
477+
type Assoc = T;
478+
}
479+
```
480+
457481
[`Candidate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_next_trait_solver/solve/assembly/struct.Candidate.html
458482
[`CandidateSource`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_next_trait_solver/solve/enum.CandidateSource.html
459483
[`fn merge_trait_candidates`]: https://github.com/rust-lang/rust/blob/e3ee7f7aea5b45af3b42b5e4713da43876a65ac9/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs#L1342-L1424

0 commit comments

Comments
 (0)