rust-lang / rust-lang/rust-clippy

Various infalliable patterns in `clippy::redundant_pattern_matching`

Open
#16,235 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The clippy::redundant_pattern_matching lint only checks for _ patterns, and not other infallible patterns such as:

  • Infallible tuple patterns e.g. (_, _)
  • Infallible enum patterns e.g. Foo::Bar where Bar is the only variant of Foo
  • Infalliable struct patterns e.g. Foo { bar: _ }

The lint should be checking for all of these.

Lint Name

clippy::redundant_pattern_matching

Reproducer

I tried this code:

#![allow(clippy::disallowed_names)]

enum Baz {
    Qux
}

struct Quux {
    #[allow(dead_code)]
    corge: bool,
}

fn main() {
    let foo = Some((2, 4));
    let bar = Some(Baz::Qux);
    let grault = Some(Quux {
        corge: true,
    });

    if let Some((_, _)) = foo {}
    if let Some(Baz::Qux) = bar {}
    if let Some(Quux { corge: _ }) = grault {}
}

I expected to receive multiple warnings from the clippy::redundant_pattern_matching lint, since this pattern matching is redundant, but instead, there was no warning.

Version
rustc 1.93.0-nightly (83e49b75e 2025-12-03)
binary: rustc
commit-hash: 83e49b75e7daf827e4390ae0ccbcb0d0e2c96493
commit-date: 2025-12-03
host: x86_64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.5

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

Start by running the provided Rust reproducer with clippy::redundant_pattern_matching enabled and inspect the lint's implementation and existing coverage. Extend the lint so the tuple, single-variant enum, and struct patterns are recognized as infallible, then verify that all three examples produce warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.