rust-lang / rust-lang/rust-clippy
Redundant if test lint
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
Here the first if test contains a return so the second if can't be true. This is usually a coding mistake that could hide a bug, so I think a lint that spots such situations is good. This lint could be complex (like firing even if the first test contains "< 3") but even basic cases like this with repeated conditions should be useful.
Lint Name
impossibile_if_branch
Category
suspicious
Advantage
No response
Drawbacks
No response
Example
fn test2(s: &[u32]) -> bool {
if s.len() < 2 {
return true;
}
if s.len() < 2 {
println!("*");
}
false
}
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
No implementation files or tests are named in the issue. Start by locating Clippy's existing suspicious lints and their test conventions, then use the Rust example as the initial acceptance case: repeated conditions after a returning branch should be reported without incorrectly flagging valid control flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100