rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.91k stars 12.68k forks source link

Fall back to more verbose error when 'expected' and 'found' are the same #73521

Open Aaron1011 opened 4 years ago

Aaron1011 commented 4 years ago

In some cases (#71723, #73520), we emit an error of the form 'expected A, found A', where the 'expected' and 'found' cases are character-for-character identical.

We could make these messages much less confusing by detecting the case where the formatted 'expected' and 'found' values are identical, and fallback to explicitly printing lifetimes when this happens. While this could result in more verbose error messages, it should help point users in the right direction. Currently, there's absolutely no indication that these issues result from a lifetime mismatch - users must either learn this from experience, or read the compiler internals.

ijackson commented 3 years ago

Also, even if you know it must be a lifetime mismatch you have to intuit (or puzzle) what is wrong (or you can sprinkle random lifetime annotations until it compiles...)

camelid commented 3 years ago

Should this be considered a duplicate of #75791?