Skip to content

FP in if_same_then_else for if-let #7579

Closed
@extrawurst

Description

@extrawurst

followup to #7383 and pinging @xFrednet

Lint name: if_same_then_else

I tried this code:

#[allow(unused_variables)]
fn main() {
    let a = true;
    let b = Some(true);
    
    if let Some(b) = b {
        println!("hello");
    }
    else if a {
        println!("hello");
    }
}

see https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c49e249051ac25681b4fe4522994a524

I expected to see this happen:
no lint warning, since I cannot express this until if-let-chains are supported

Instead, this happened:

Checking playground v0.0.1 (/playground)
error: this `if` has identical blocks
  --> src/main.rs:6:24
   |
6  |       if let Some(b) = b {
   |  ________________________^
7  | |         println!("hello");
8  | |     }
   | |_____^
   |
   = note: `#[deny(clippy::if_same_then_else)]` on by default
note: same as this
  --> src/main.rs:9:15
   |
9  |       else if a {
   |  _______________^
10 | |         println!("hello");
11 | |     }
   | |_____^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else

error: could not compile `playground` due to previous error

Meta

  • cargo clippy -V: clippy 0.1.56 (0035d9d 2021-08-16)
  • rustc -Vv:
rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-apple-darwin
release: 1.54.0
LLVM version: 12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveP-highPriority: High

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions