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

FP in if_same_then_else for if-let #7579

Closed
extrawurst opened this issue Aug 17, 2021 · 2 comments · Fixed by #8297
Closed

FP in if_same_then_else for if-let #7579

extrawurst opened this issue Aug 17, 2021 · 2 comments · Fixed by #8297
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have P-high Priority: High

Comments

@extrawurst
Copy link

extrawurst commented Aug 17, 2021

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
@extrawurst extrawurst added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 17, 2021
@camsteffen camsteffen added the P-high Priority: High label Aug 23, 2021
@camsteffen
Copy link
Contributor

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

@camsteffen camsteffen added the E-medium Call for participation: Medium difficulty level problem and requires some initial experience. label Aug 23, 2021
@flip1995
Copy link
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 🤔

bors added a commit that referenced this issue Jan 16, 2022
Don't lint `if_same_then_else` with `if let` conditions

fixes #7579

changelog: Don't lint `if_same_then_else` with `if let` conditions
@bors bors closed this as completed in 537a7f3 Jan 17, 2022
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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have P-high Priority: High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants