rust-lang / rust-lang/rust-clippy
Detects if/else chains with redundant conditions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detects when the if condition of if/else chains are redundant or if a part of the chain will never execute.
Advantage
This type of code represents likely a bug in either the condition, or allows for an entire if/else arm to be removed.
Drawbacks
Implementation complexity? For numeric types and comparisons, this would be easy to implement, for other types not so much.
Example
fn main() {
let x = 42;
if x > 10 {
println!("1");
} else if x == 42 { // This will always be true if the above is true, and will always be false if the above is false
println!("2"); // unreachable code
}
}
fn main() {
let x = 42;
if x > 10 {
println!("1");
} else if true {
if x > 10 {
println!("2"); // unreachable code
}
}
}
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 with the two Rust examples in the issue and define the expected diagnostics for redundant conditions and unreachable if/else arms. The issue names no source files, tests, or entry points, so locating a comparable Clippy lint and its tests is required before implementation. Done means the specified cases are detected without overreaching into unsupported condition types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100