]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: allow `clippy::collapsible_match` globally
authorMiguel Ojeda <ojeda@kernel.org>
Sun, 26 Apr 2026 14:42:00 +0000 (16:42 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 30 Apr 2026 21:21:31 +0000 (23:21 +0200)
The `clippy::collapsible_match` lint [1] can make code harder to read
in certain cases [2], e.g.

      CLIPPY P rust/libmacros.so - due to command line change
    warning: this `if` can be collapsed into the outer `match`
      --> rust/pin-init/internal/src/helpers.rs:91:17
       |
    91 | /                 if nesting == 1 {
    92 | |                     impl_generics.push(tt.clone());
    93 | |                     impl_generics.push(tt);
    94 | |                     skip_until_comma = false;
    95 | |                 }
       | |_________________^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
       = note: `-W clippy::collapsible-match` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::collapsible_match)]`
    help: collapse nested if block
       |
    90 ~             TokenTree::Punct(p) if skip_until_comma && p.as_char() == ','
    91 ~                 && nesting == 1 => {
    92 |                     impl_generics.push(tt.clone());
    93 |                     impl_generics.push(tt);
    94 |                     skip_until_comma = false;
    95 ~                 }
       |

The lint does not have much upside -- when the suggestion may be a good
one, it would still read fine when nested anyway. And it is the kind of
lint that may easily bias people to just apply the suggestion instead
of allowing it.

[ In addition, as Gary points out [3], the suggestion is also wrong [4] and
  in the process of being fixed [5], possibly for Rust 1.97.0:

Link: https://lore.kernel.org/rust-for-linux/DI3YV94TH9I3.1SOHW51552497@garyguo.net/
Link: https://github.com/rust-lang/rust-clippy/issues/16875
Link: https://github.com/rust-lang/rust-clippy/pull/16878
    - Miguel ]

Thus just let developers decide on their own.

Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Link: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
Link: https://lore.kernel.org/rust-for-linux/CANiq72nWYJna_hdFxjQCQZK6yJBrr1Mb86iKavivV0U0BgufeA@mail.gmail.com/
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260426144201.227108-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Makefile

index e27c91ea56fcf8895660d2afe90042e71f37ec3b..621d84aa4700d8528b4c634620319cdeb8fda407 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -486,6 +486,7 @@ export rust_common_flags := --edition=2021 \
                            -Wclippy::as_ptr_cast_mut \
                            -Wclippy::as_underscore \
                            -Wclippy::cast_lossless \
+                           -Aclippy::collapsible_match \
                            -Wclippy::ignored_unit_patterns \
                            -Aclippy::incompatible_msrv \
                            -Wclippy::mut_mut \