RS.CLIPPY.USELESS_LET_IF_SEQ
Unidiomatic `let mut` declaration followed by initialization in `if`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: useless_let_if_seq. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for variable declarations immediately followed by a conditional affectation.
Why is this bad?
This is not idiomatic Rust.
Example
let foo;
if bar() {
foo = 42;
} else {
foo = 0;
}
let mut baz = None;
if bar() {
baz = Some(42);
}
should be written
let foo = if bar() {
42
} else {
0
};
let baz = if bar() {
Some(42)
} else {
None
};