Skip to content

collapsible_else_if lint false positive #14722

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

Closed
sabify opened this issue May 1, 2025 · 1 comment · Fixed by #14730
Closed

collapsible_else_if lint false positive #14722

sabify opened this issue May 1, 2025 · 1 comment · Fixed by #14730
Assignees
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

@sabify
Copy link

sabify commented May 1, 2025

Summary

There is a bug in the collapsible_else_if lint that shows an irrelevant warning about collapsing else if statements when it shouldn't.

Lint Name

collapsible_else_if

Reproducer

I tried this code:

fn main() {
    let x = if true {
        Some(1)
    } else {
        if true {
            println!("Some debug information");
        };
        None
    };
}

I saw this happen:

warning: this `else { if .. }` block can be collapsed
 --> src/main.rs:4:12
  |
4 |       } else {
  |  ____________^
5 | |         if true {
6 | |             println!("Some debug information");
7 | |         };
8 | |         None
9 | |     };
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if
  = note: `#[warn(clippy::collapsible_else_if)]` on by default
help: collapse nested if block
  |
4 ~     } else if true {
5 +         println!("Some debug information");
6 ~     };
  |

I expected to see this happen:

No warning.

Version

rustc 1.88.0-nightly (b45dd71d1 2025-04-30)
binary: rustc
commit-hash: b45dd71d1824f176fba88f6c40467030a16afa2c
commit-date: 2025-04-30
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.2

Additional Labels

No response

@sabify sabify 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 May 1, 2025
@profetia
Copy link
Contributor

profetia commented May 2, 2025

@rustbot claim

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

Successfully merging a pull request may close this issue.

2 participants