Closed
Description
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