Elided lifetimes in error messages can be incorrect, as well as misleading #87763
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a08f48d6e07780f4d6a881eddf3459d2
The current output is:
Ideally the output should look like:
Right now, the error message just outputs
&S
several times, yet there are three different lifetime variables involved here:'_1
, which is the lifetime for the reference that isT
'_2
, which is the lifetime for the returned reference that isSelf
'_3
the lifetime parameter for thefrom
function in the impl block (which I guess is ~hidden by afor<'_3>
)Because it always elides lifetimes in the error message, the error message produces a false statement of what it expected (it claims to expect
fn(&S) -> &S
, which is untrue), and presents textually identical "expected" and "found" types.(Incidentally, the help section about
consider borrowing
is actually, perhaps accidentally, helpful -- if you move the references to thefn
declaration, then they have the same lifetime elision rules as theimpl
, and everything lines up.)The text was updated successfully, but these errors were encountered: