rust-lang / rust-lang/rust-clippy

`clippy::single_match` suggestion does not compile when the expression contains un-chainable comparison operators

Open
#17,756 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-suggestion-causes-error
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.