rust-lang / rust-lang/rust-clippy
FN implicit if_same_then_else
Open
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
fn main() {
println!("{:?}", func(4));
}
fn func(n: i32) -> bool {
if n < 2 {
return true;
} else if n > 2 {
return false;
}
return false; // return outside of conditions
}
this code is basically identical to
fn main() {
println!("{:?}", func(4));
}
fn func(n: i32) -> bool {
if n < 2 {
return true;
} else if n > 2 {
return false;
} else { // return moved into else {}
return false;
}
}
but only the latter triggers the if_same_then_else warning.
Should the first example trigger a warning as well?
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 if_same_then_else lint and its existing tests, then compare how the two Rust examples are analyzed. Add a regression case for the first example if it should produce the same warning, and run the lint's tests to verify the result.
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