RS.CLIPPY.IF_NOT_ELSE
`if` branches that could be swapped so no negation operation is necessary on the condition
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: if_not_else. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of ! or != in an if condition with an
else branch.
Why is this bad?
Negations reduce the readability of statements.
Example
if !v.is_empty() {
a()
} else {
b()
}
Could be written:
if v.is_empty() {
b()
} else {
a()
}