rust/clippy_utils
Alex Macleod a6dfbb3524
Stop inserting redundant parenthesis around desugared match expressions (#16102)
Currently the `sugg` utility treats all `ExprKind::Match` expressions as
potentially needing brackets, and therefore many lints will add
parenthesis around them. However this includes desugared match
expressions like the `?` and `.await` operators.

In this PR I have updated the utility to only treat match expressions
which include a code block as needing parenthesis, as the other types
have similar precedence rules and expectations to things like member
access and I think can be treated like as such.

While this change is small on paper it touches a large amount of code
due to changing a cross cutting concern, I am happy to add additional
tests if we think it is needed, but I wanted to get a feel for if this
is even a sensible change to be doing and what the expectations were
around the level of testing needed before investing more time into it.

Regarding not putting a specific lint in the changelog, determining all
the lints this could possibly effect would be possible but take some
time, and I wonder if it would be a bit too noisy in the changelog. Open
to suggestions about how best to address that.

fixes rust-lang/rust-clippy#16045

changelog: stop inserting unnecessary brackets around `x?` and `x.await`
expressions in suggestions
2025-11-27 18:49:07 +00:00
..
src Stop inserting redundant parenthesis around desugared match expressions (#16102) 2025-11-27 18:49:07 +00:00
Cargo.toml Merge commit 'c936595d17' into clippy-subtree-update 2025-10-31 19:15:42 +01:00
README.md Bump nightly version -> 2025-11-15 2025-11-15 00:37:56 +01:00

clippy-utils

Helpful tools for writing lints, provided as they are used in Clippy.

Usage

This crate is only guaranteed to build with this nightly toolchain:

nightly-2025-11-14

To use clippy-utils in your lint, add the following to your Cargo.toml:

clippy_utils = "0.1.XY"

XY is the version of the nightly toolchain above and can be determined with rustc +nightly-YYYY-MM-DD -V.

⚠️ Stability ⚠️

No stability guarantees are made for this crate! Use at your own risk.

Function signatures can change or be removed without replacement without any prior notice.

LICENSE

Copyright 2014-2025 The Rust Project Developers

Licensed under the Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> or the MIT license <https://opensource.org/licenses/MIT>, at your option. Files in the project may not be copied, modified, or distributed except according to those terms.