rust-lang / rust-lang/rust-clippy
collapsible_if: comparison chain `x || y` -> `x` -> `y` can be optimized to `x && y`
Open
Nobody has claimed this yet.
A-lint
C-enhancement
L-complexity
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I stumbled upon such a piece of code (x and y represent bool expressions):
if x || y {
if x {
if y {
unimplemented!("x and y");
} else {
unimplemented!("x");
}
} else {
unimplemented!("y");
}
}
which can be optimized to
if x && y {
unimplemented!("x and y");
} else if x {
unimplemented!("x");
} else if y {
unimplemented!("y");
}
The combination of nested if expressions
x || y->x->yequalsx && yx || y->xequalsxx || y->yequalsy
or
x || y->x->yequals(x || y) && x && yx || y->xequals(x || y) && xx || y->yequals(x || y) && y
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 collapsible_if lint named in the issue title and compare its existing behavior with the nested boolean examples in the issue body. Determine how the lint's tests represent these condition chains; done means the intended transformations are implemented with regression coverage and their behavior is reviewed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100