rust-lang / rust-lang/rust-clippy
If-same-then-else bug for chained inequality expression
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I tried this code:
if c.x < max_x && c.x > min_x && c.y <= max_y && c.y >= min_y {
true
} else if c.x <= max_x && c.x >= min_x && c.y < max_y && c.y > min_y {
true
} else {
false
}
I expected to see this happen: everything works fine. Clippy does need to not complain. Both inequality chains within the two if conditions are different from each other.
Instead, this happened:
this `if` has identical blocks
--> ghost\src\algorithms\intersection\segment_any.rs:119:74
|
119 | } else if c.x <= max_x && c.x >= min_x && c.y < max_y && c.y > min_y {
| __________________________________________________________________________^
120 | | PointSegResult::Inside
121 | | } else {
| |_____^
|
note: same as this
--> ghost\src\algorithms\intersection\segment_any.rs:117:74
|
117 | } else if c.x < max_x && c.x > min_x && c.y <= max_y && c.y >= min_y {
| __________________________________________________________________________^
118 | | PointSegResult::Inside
119 | | } else if c.x <= max_x && c.x >= min_x && c.y < max_y && c.y > min_y {
| |_____^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
Meta
cargo clippy -V: e.g. clippy 0.0.212 (18bf6b4f0 2020-10-07)rustc -Vv:
rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-pc-windows-msvc
release: 1.47.0
LLVM version: 11.0
There is no need for a backtrace hence I omitted it.
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 reproducing the reported example with cargo clippy and inspect the if_same_then_else lint entry point. Compare the two chained inequality conditions in the report and verify that distinct conditions no longer produce an identical-block warning; the existing reproduction is in ghost\src\algorithms\intersection\segment_any.rs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100