Re: [RFC PATCH] rust: kernel: clean explicit lifetimes that can be elided

From: Alice Ryhl
Date: Mon Oct 14 2024 - 08:15:08 EST


On Sun, Oct 13, 2024 at 1:13 AM Miguel Ojeda <ojeda@xxxxxxxxxx> wrote:
>
> 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: https://github.com/rust-lang/rust-clippy/pull/13286 [1]
> Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
> ---
> Do we want this in general, or just in some cases? There is an issue about this
> where we may want to leave some feedback:
>
> https://github.com/rust-lang/rust-clippy/issues/13514

If this lint lands for real, then this change LGTM:

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

However, I don't think the lint is useful. I would rather that we are
able to allow this lint.

Alice