rust-lang / rust-lang/rust-clippy
redundant_pattern_matching failes to check whether contained value are used.
Nobody has claimed this yet.
- 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
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
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