rust-lang / rust-lang/rust-clippy

redundant_pattern_matching failes to check whether contained value are used.

Open
#12,329 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

I found a example of redundant pattern matching in my code that wasn't picked up by clippy.

Lint Name

redundant_pattern_matching

Reproducer

I tried this code:

#[deny(clippy::redundant_pattern_matching)]
pub fn missing_warning(input: &str) -> bool {
    // This is the match I expected 'redundant_pattern_matching' to warn me about.
    let _result = match input.parse::<u32>() {
        Ok(_) => input,
        Err(_) => return false
    };
    true
}

I expected to see this happen:
Running cargo clippy should trigger an error and provide a suggestion in the form of:

pub fn expected_fix(input: &str) -> bool {
    let _result = if input.parse::<u32>().is_ok() { input } else { return false }
}

Instead, this happened:
Running cargo clippy did not report any errors.

Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02e
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6

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 locating the implementation and tests for the redundant_pattern_matching lint, then run cargo clippy on the provided Rust reproducer. Confirm that the lint recognizes when match arms contain used values and reports the expected simplification without changing behavior.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.