Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nevsden opened this issue Nov 3, 2020 · 1 comment
Open

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

Nevsden opened this issue Nov 3, 2020 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Nevsden
Copy link

Nevsden commented Nov 3, 2020

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.
@Nevsden Nevsden added the C-bug Category: Clippy is not doing the correct thing label Nov 3, 2020
@giraffate
Copy link
Contributor

related issue: #3770

@phansch phansch added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants