RS.CLIPPY.NEEDLESS_BOOL

If-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`

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. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for expressions of the form if c { true } else { false } (or vice versa) and suggests using the condition directly.

Why is this bad?

Redundant code.

Known problems

Maybe false positives: Sometimes, the two branches are painstakingly documented (which we, of course, do not detect), so they may have some value. Even then, the documentation can be rewritten to match the shorter code.

Example

if x {
    false
} else {
    true
}

Use instead:

!x