rust-lang / rust-lang/rust-clippy
`clippy::single_match` suggestion does not compile when the expression contains un-chainable comparison operators
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When using a match statement with an inequality like 1 < 2 and boolean branches, clippy suggests an if statement of the form if 1 < 2 == true which is not legal as the == and < operators cannot be chained and so require parenthesis [source].
Reproducer
Code:
match 1 < 2 {
true => (),
false => (),
};
https://rust.godbolt.org/z/eacKdYEds
Current output:
if 1 < 2 == true { () };
https://rust.godbolt.org/z/TfzTz6rT6
Desired output:
if (1 < 2) == true { () };
or
if 1 < 2 { () };
Version
rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the implementation and tests for clippy::single_match; begin by reproducing the reported match expression and inspecting how its suggestion is built. Done means the suggested if expression is valid Rust for the inequality case while preserving the intended behavior; run the relevant Clippy tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100