-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
I used cargo clippy --fix and unittests failed as a result, because the code didn't do the same as before.
Reproducer
Cargo.toml:
[package]
name = "testcase"
edition = "2024"
[features]
bundle-translations = []
src/main.rs:
fn main() {
let f = 1;
let g = Some(1);
let _h = Some(2);
let mut ret = 0;
// [...]
// Nothing in this if statement should execute
if f == 0 {
if let Some(v) = g {
ret = v;
}
#[cfg(feature = "bundle-translations")]
if let Some(v) = _h {
ret = v;
}
}
assert!(ret == 0);
} cargo build --all-features ; cargo run, the assert passes.
clippy --fix changes this to
// Nothing in this if statement should execute
if f == 0
&& let Some(v) = g {
ret = v;
}
#[cfg(feature = "bundle-translations")]
if let Some(v) = _h {
ret = v;
}
assert!(ret == 0);
Which means that when building the code with the bundle-translations feature enabled, the second if() will be evaluated, unlike before, and ret will be 2 instead of 0.
Pretty sure clippy got confused by the fact that the code was not enabled when it ran (the feature is off by default), but changing behavior when the feature is set is surely a --fix bug.
Version
rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.91.1
LLVM version: 21.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way