Skip to content

False positive in if_same_then_else lint #7383

@Shnatsel

Description

@Shnatsel

Lint name: if_same_then_else

I tried this code:

fn main() {
    let a = 0;
    let b = 5;
    let some_check: bool = if a == 0 && b == 0 {
        true
    } else if a < b {
        true
    } else {
        match (a, b) {
            (16, 0) => true,
            _ => false
        }
    };
}

(this is a minimal example adapted from real code; real code can be found here)

I expected to see this happen: no warnings

Instead, this happened:

error: this `if` has identical blocks
 --> src/main.rs:4:48
  |
4 |       let some_check: bool = if a == 0 && b == 0 {
  |  ________________________________________________^
5 | |         true
6 | |     } else if a < b {
  | |_____^
  |
  = note: `#[deny(clippy::if_same_then_else)]` on by default
note: same as this
 --> src/main.rs:6:21
  |
6 |       } else if a < b {
  |  _____________________^
7 | |         true
8 | |     } else {
  | |_____^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else

Meta

  • cargo clippy -V: both 0.1.54 (2021-06-19 150fad3) and clippy 0.1.52 (9bc8c42 2021-05-09)
  • rustc -Vv:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-unknown-linux-gnu
release: 1.52.1
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions