

Show detailed expected/found types in error message when trait paths are the sam...
source link: https://github.com/rust-lang/rust/pull/89633
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Fixes #65230.
Issue solved by this PR
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.
Recommend
-
36
Summary NullPointerExceptions are freqently encountered developing or maintaining a Java application. NullPointerExceptions often don't contain a message. This complicates finding the cause of the exception.
-
7
When the internet works as it should, it couldn’t be more useful. Unfortunately, there are times when it simply refuses to do its job. You make a simple request and all you get in return is a vague error message. Case in point, t...
-
6
Copy link Contributor ptrojahn commented
-
10
Copy link Contributor
-
6
New issue Don't lint ptr_arg for &mut _ types in trait items #8369
-
6
Copy link Contributor compiler-errors...
-
10
A logging wrapper around PreparedStatement to provide detailed info upon error May 23, 2009 In my java web application I use JD...
-
7
Conversation Contributor This i...
-
12
Stabilization report This report proposes the stabilization of #![feature(return_position_impl_trait_in_trait)] (RPITIT...
-
6
Realme 12 Pro series' cameras detailed, launch expected this month Realme held a
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK