Confusing lifetime diagnostics for trait impl #115903
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
No response
Rationale and extra context
The lifetime mismatch occurs because for
y
, the lifetime of the trait (anonymous) will not outlive the lifetime of the impl ('static
). However, the diagnosis is making reference to (the lifetime of?)x
, which does not have anything to do with the mismatch.If I define an explicit lifetime for
x
in the impl fn:It refers to some anonymouse lifetime using the span of the whole impl function signature.
Something similar happens if I remove the
x
argument (from both trait and impl):Other cases
No response
Anything else?
I think the issue might be in the
msg_span_from_named_region
function fromcompiler/rustc_infer/src/infer/error_reporting/mod.rs
:rust/compiler/rustc_infer/src/infer/error_reporting/mod.rs
Lines 230 to 244 in 341ef15
In this case,
name
iskw::UnderscoreLifetime
andgenerics.get_named(name)
will find the span of the first anonymous lifetime. If there is none, it will fallback to the span ofscope
(the whole function signature).The text was updated successfully, but these errors were encountered: