-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Extend needless_lifetimes
to suggest eliding impl
lifetimes
#13286
Conversation
☔ The latest upstream changes (presumably #13390) made this pull request unmergeable. Please resolve the merge conflicts. |
07b5310
to
c64794a
Compare
☔ The latest upstream changes (presumably #13440) made this pull request unmergeable. Please resolve the merge conflicts. |
c64794a
to
05cdfad
Compare
Hey, @Alexendoo. Short of a full review, could I ask what your thoughts are on this PR? Also, I would understand if your plate is too full. Would you like be to ask rustbot to select another reviewer? |
☔ The latest upstream changes (presumably #13442) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry yeah been busy, I think I've reviewed some stuff for this lint but it's been a while and I've forgotten most of it 😅 The change seems like a natural extension but it does make me wonder if we should split the lint into cases that need Some of the added |
05cdfad
to
51b5272
Compare
NP. Thanks very much for your comments.
👍
I was using |
clippy_lints/src/lifetimes.rs
Outdated
let mut checker = LifetimeChecker::<hir_nested_filter::None>::new(cx, hs); | ||
let mut checker = LifetimeChecker::<hir_nested_filter::None>::new(cx, def_ids); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could collect into the HashMap
LifetimeChecker
wants directly rather than creating a temporary Vec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe pass the Generics
into LifetimeChecker::new
and have the collect done in there? (Maybe this is what you were suggesting.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking of passing in FxHashMap<LocalDefId, Vec<Usage>>
but yeah yours is better since there's two places the collect is being done already
Thanks! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Thank you! |
Tracking lifetime support in impls was added in recent nightly clippy. rust-lang/rust-clippy#13286
Tracking lifetime support in impls was added in recent nightly clippy. rust-lang/rust-clippy#13286
I'm not entirely sure I like the non-uniformity of giving a name to the lifetime in the type only if it is used in the body, but I do appreciate reducing the generic parameter count in many impl blocks, and all of the actual cases seem fine. This additional lint came from <rust-lang/rust-clippy#13286> “Extend needless_lifetimes to suggest eliding impl lifetimes”.
In nightly Clippy (i.e. Rust 1.83.0), the `needless_lifetimes` lint has been extended [1] to suggest eliding `impl` lifetimes, e.g. error: the following explicit lifetimes could be elided: 'a --> rust/kernel/list.rs:647:6 | 647 | impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'a, T, ID> {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `-D clippy::needless-lifetimes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | 647 - impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'a, T, ID> {} 647 + impl<T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'_, T, ID> {} Thus clean them. Link: rust-lang/rust-clippy#13286 [1] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
In nightly Clippy (i.e. Rust 1.83.0), the `needless_lifetimes` lint has been extended [1] to suggest eliding `impl` lifetimes, e.g. error: the following explicit lifetimes could be elided: 'a --> rust/kernel/list.rs:647:6 | 647 | impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'a, T, ID> {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `-D clippy::needless-lifetimes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | 647 - impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'a, T, ID> {} 647 + impl<T: ?Sized + ListItem<ID>, const ID: u64> FusedIterator for Iter<'_, T, ID> {} Thus clean them. Link: rust-lang/rust-clippy#13286 [1] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Example:
The main change is in how
impl
lifetime uses are tracked. Previously, a hashmap was created, and lifetimes were removed from the hashmap as their uses were discovered. However, the uses are needed to generate elision suggestions. So, now, uses are added to the hashmap as they are discovered.The PR is currently organized as six commits, which I think are self-explanatory:
needless_lifetimes
to suggest elidingimpl
lifetimesclippy_lints
andclippy_utils
needless_lifetimes
testr? @Alexendoo (I think you are
needless_lifetimes
' primary author? Sorry if I have this wrong.)changelog: Extend
needless_lifetimes
to suggest elidingimpl
lifetimes