RS.CLIPPY.NEEDLESS_BOOL_ASSIGN
Setting the same boolean variable in both branches of an if-statement
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_bool_assign. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for expressions of the form if c { x = true } else { x = false }
(or vice versa) and suggest assigning the variable directly from the
condition.
Why is this bad?
Redundant code.
Example
if must_keep(x, y) {
skip = false;
} else {
skip = true;
}
Use instead:
skip = !must_keep(x, y);