RS.CLIPPY.COLLAPSIBLE_ELSE_IF

Nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: collapsible_else_if. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for collapsible else { if ... } expressions that can be collapsed to else if ....

Why is this bad?

Each if-statement adds one level of nesting, which makes code look more complex than it really is.

Example


if x {
    ...
} else {
    if y {
        ...
    }
}

Should be written:

if x {
    ...
} else if y {
    ...
}