Skip to content

FP in if_same_then_else for if-let #7579

@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

Activity

added
C-bugCategory: Clippy is not doing the correct thing
I-false-positiveIssue: The lint was triggered on code it shouldn't have
on Aug 17, 2021
camsteffen

camsteffen commented on Aug 23, 2021

@camsteffen
Contributor

This is a regression from rust-lang/rust#80357.

added
E-mediumCall for participation: Medium difficulty level problem and requires some initial experience.
on Aug 23, 2021
flip1995

flip1995 commented on Aug 24, 2021

@flip1995
Member

There were allows added for this lint in our tests in rust-lang/rust#80357

These may have been added to get around this bug 🤔

added 2 commits that reference this issue on Jan 16, 2022
f230cdc
537a7f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @extrawurst@camsteffen@flip1995

      Issue actions

        FP in if_same_then_else for if-let · Issue #7579 · rust-lang/rust-clippy