Suggestion for single_use_lifetimes
suggests code that fails to compile
#117965
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-bug
Category: This is a bug.
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
F-lint-single_use_lifetimes
`single_use_lifetimes` lint
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-diagnostics
Working group: Diagnostics
playground
This code, as expected, triggers the lint. This is the compiler output:
Applying the suggested change, we then get a lifetime error.
In this specific instance,
&'a str
must also be changed to&str
. That'll then trigger the lint onimpl<'a> Data<'a>
, with no ensuing issues.I have not checked this, but I my suspicion is any place where a lifetime bound is also present in the return type (or possibly even a parameter) will result in a similar failure to compile the suggested code. Figuring out which lifetimes to suggest removal of in other parts of the function signature probably isn't straightforward.
This example is not theoretical, unfortunately. I ran into this in real-world code and it caused me quite a bit of time to figure out. The example is the minimal reproduction of the bad suggestion.
The text was updated successfully, but these errors were encountered: