-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveS-fixedStatus: Issues that got fixed, waiting to be closed as completedStatus: Issues that got fixed, waiting to be closed as completed
Description
Summary
When something is configured ut between two if, it's ignored by the collapsible_if
and it suggest an invalid fix
Lint Name
collapsible_if
Reproducer
I tried this code:
fn main() {
#[allow(unused_mut)]
let mut inner = false;
if true {
#[cfg(false)]
{ inner = true; }
if inner {
println!("hello");
}
}
}
I saw this happen:
warning: this `if` statement can be collapsed
--> src/main.rs:4:5
|
4 | / if true {
5 | | #[cfg(false)]
6 | | { inner = true; }
7 | | if inner {
... |
10 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
= note: `#[warn(clippy::collapsible_if)]` on by default
help: collapse nested if block
|
4 ~ if true
5 | #[cfg(false)]
6 | { inner = true; }
7 ~ && inner {
8 | println!("hello");
9 ~ }
|
I expected to see this happen: no lint
Version
rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: aarch64-apple-darwin
release: 1.89.0
LLVM version: 20.1.7
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveS-fixedStatus: Issues that got fixed, waiting to be closed as completedStatus: Issues that got fixed, waiting to be closed as completed