Skip to contentSkip to conversation

rust: allow `clippy::needless_lifetimes`

PATCH Applied Miguel Ojeda 4 participants 5 messages Nov 16, 2024 – Nov 24, 2024

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: allow `clippy::needless_lifetimes`

In beta 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> {}

A possibility would have been to clean them -- the RFC patch [2] did this, while asking if we wanted these cleanups. There is an open issue
[3] in Clippy about being able to differentiate some of the new cases, e.g. those that do not involve introducing '_. Thus it seems others feel similarly.

Thus, for the time being, we decided to allow the lint.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index a9e723cb0596..00a444603fb1 100644
@@ -456,6 +456,7 @@ export rust_common_flags := --edition=2021 \
 			    -Wclippy::mut_mut \
 			    -Wclippy::needless_bitwise_bool \
 			    -Wclippy::needless_continue \
+			    -Aclippy::needless_lifetimes \
 			    -Wclippy::no_mangle_with_rust_abi \
 			    -Wclippy::undocumented_unsafe_blocks \
 			    -Wclippy::unnecessary_safety_comment \

base-commit: b2603f8ac8217bc59f5c7f248ac248423b9b99cb

Signature · 1 line
2.47.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Miguel Ojeda

In beta 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> {}

A possibility would have been to clean them -- the RFC patch [2] did this, while asking if we wanted these cleanups. There is an open issue
[3] in Clippy about being able to differentiate some of the new cases, e.g. those that do not involve introducing '_. Thus it seems others feel similarly.

Quoted 6 lines

Thus, for the time being, we decided to allow the lint.

Does this need any backports to keep old kernels warning-free on new compilers?

#2 lore raw
Quoted 2 lines · Alice Ryhl

Does this need any backports to keep old kernels warning-free on new compilers?

+1, for stable, yeah, if we want to keep it Clippy-clean (which I think we should, especially given it is straightforward). I will send it.

For the LTSs, which only support a single compiler, there is no need.

Cheers,
Miguel

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Miguel Ojeda
Quoted 23 lines · Miguel Ojeda

In beta 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> {}

A possibility would have been to clean them -- the RFC patch [2] did this, while asking if we wanted these cleanups. There is an open issue
[3] in Clippy about being able to differentiate some of the new cases, e.g. those that do not involve introducing '_. Thus it seems others feel similarly.

Quoted 7 lines

Thus, for the time being, we decided to allow the lint.

---

Best regards,
Andreas Hindborg

Applied
#4 lore raw
In reply to Miguel Ojeda
Quoted 24 lines · Miguel Ojeda

In beta 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> {}

A possibility would have been to clean them -- the RFC patch [2] did this, while asking if we wanted these cleanups. There is an open issue
[3] in Clippy about being able to differentiate some of the new cases, e.g. those that do not involve introducing '_. Thus it seems others feel similarly.

Quoted 6 lines

Thus, for the time being, we decided to allow the lint.

Applied to rust-next so that no one gets warnings on Thursday under CLIPPY=1 -- thanks everyone!

Cheers,
Miguel