Re: [PATCH 1/2] rust: allow `clippy::collapsible_match` globally

From: Gary Guo

Date: Mon Apr 27 2026 - 09:23:54 EST


On Sun Apr 26, 2026 at 3:42 PM BST, Miguel Ojeda wrote:
> 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.

It's also just wrong.

pattern => {
if x {
...
}
}

is not equal to

pattern if x => { ... }

because the former prevents other arms later (e.g. a `_`) from being to act
while the latter doesn't.

See https://github.com/rust-lang/rust-clippy/pull/16878

>
> Thus just let developers decide on their own.
>
> Cc: stable@xxxxxxxxxxxxxxx # 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 [1]
> Link: https://lore.kernel.org/rust-for-linux/CANiq72nWYJna_hdFxjQCQZK6yJBrr1Mb86iKavivV0U0BgufeA@xxxxxxxxxxxxxx/ [2]
> Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx>

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

Best,
Gary

> ---
> Makefile | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Makefile b/Makefile
> index 54e1ae602000..e2a810bc4409 100644
> --- 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 \
>
> base-commit: 897d54018cc9aa97fd1529ca08a53b429d05a566