rust-lang / rust-lang/rust-clippy
if_same_then_else should ignore empty bodies
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Example:
if x.ident == y {
} else if first && (*y == "core" || *y == "alloc") && x.ident == "std" {
} else {
return false;
}
Yes, this is just a chained if expression. There are different ways to write it; as a single expression with/without brackets, via let bindings (though it's less clear if these take advantage of lazy evaluation), even via a match expression.
This is all about style (which, in my opinion, Clippy does not deserve a say in) and nothing about efficiency or redundancy.
Lint Name
if_same_then_else
Reproducer
No response
Version
No response
Additional Labels
No response
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 at the if_same_then_else lint implementation and its existing tests in rust-clippy. Trace how chained if branches are classified, then add coverage for branches with empty bodies. Done means the lint ignores empty branches in the reported pattern while preserving its existing behavior for non-empty branches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100