-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
needless_lifetimes
removes lifetimes that are actually necessary
#12908
Comments
Looks like the lint's logic for checking if a lifetime is referred to in the function body stops at closures (probably a visitor not configured to enter nested bodies). Minimized repro: fn f<'a>(s: &'a str) {
|| { let _: &'a str; };
} |
Hey @y21 I have a bunch of other issues on |
Feel free to take it, I wasn't planning to work on it (am currently fairly busy with other things). Just decided to minimize this since the original reproducer was not minimal and relied on external types/deps |
Just ran into this (together with #12789), and it seems like a local https://github.com/ruffle-rs/ruffle/actions/runs/12055200721/job/33615027011?pr=18761#step:6:1046 |
I am also getting a false positive with this lint. Here is an example on Rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=04c989b7eb0429e16fca2f21a83e79de The gist here is that I have a trait that requires a certain lifetime from a function that can return various properties, but one property uses a getter that actually just translates an enum to static strings. Clippy thinks that function's lifetime can be elided but it actually cannot be, at least not in Rust's current lifetime checking. |
Summary
The lifetimes seem to be unavoidable in the function I defined, but clippy still suggests removing them. If I run
cargo clippy --fix
, the resulting code fails to compile.Lint Name
needless_lifetimes
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No suggestions, as the lifetime annotation is necessary here as far as I know.
Version
Additional Labels
@rustbot label +l-suggestion-causes-error
The text was updated successfully, but these errors were encountered: