rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.28k stars 1.52k forks source link

If-same-then-else bug for chained inequality expression #6285

Open Nevsden opened 3 years ago

Nevsden commented 3 years ago

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

giraffate commented 3 years ago

related issue: https://github.com/rust-lang/rust-clippy/issues/3770