68dfa07e3b
Show detailed expected/found types in error message when trait paths are the same Fixes #65230. ### Issue solved by this PR ```rust trait T { type U; fn f(&self) -> Self::U; } struct X<'a>(&'a mut i32); impl<'a> T for X<'a> { type U = &'a i32; fn f(&self) -> Self::U { self.0 } } fn main() {} ``` Compiler generates the following note: ``` note: ...so that the types are compatible --> test.rs:10:28 | 10 | fn f(&self) -> Self::U { | ____________________________^ 11 | | self.0 12 | | } | |_____^ = note: expected `T` found `T` ``` This note is not useful since the expected type and the found type are the same. ### How this PR solve the issue When the expected type and the found type are exactly the same in string representation, the note falls back to the detailed string representation of trait ref: ``` note: ...so that the types are compatible --> test.rs:10:28 | 10 | fn f(&self) -> Self::U { | ____________________________^ 11 | | self.0 12 | | } | |_____^ = note: expected `<X<'a> as T>` found `<X<'_> as T>` ``` So that a user can notice what was different between the expected one and the found one. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |