public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <christian@brauner.io>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: allow `clippy::collapsible_match` globally
Date: Mon, 27 Apr 2026 14:20:48 +0100	[thread overview]
Message-ID: <DI3YV94TH9I3.1SOHW51552497@garyguo.net> (raw)
In-Reply-To: <20260426144201.227108-1-ojeda@kernel.org>

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@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 [1]
> Link: https://lore.kernel.org/rust-for-linux/CANiq72nWYJna_hdFxjQCQZK6yJBrr1Mb86iKavivV0U0BgufeA@mail.gmail.com/ [2]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Gary Guo <gary@garyguo.net>

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


  parent reply	other threads:[~2026-04-27 13:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-26 14:42 [PATCH 1/2] rust: allow `clippy::collapsible_match` globally Miguel Ojeda
2026-04-26 14:42 ` [PATCH 2/2] rust: allow `clippy::collapsible_if` globally Miguel Ojeda
2026-04-27 13:21   ` Gary Guo
2026-04-27 13:20 ` Gary Guo [this message]
2026-04-30 21:22 ` [PATCH 1/2] rust: allow `clippy::collapsible_match` globally Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DI3YV94TH9I3.1SOHW51552497@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=christian@brauner.io \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox