RS.CLIPPY.COLLAPSIBLE_IF

Nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`

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

What it does

Checks for nested if statements which can be collapsed by &&-combining their conditions.

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 {
    if y {
        // ...
    }
}

Use instead:

if x && y {
    // ...
}

Configuration

  • lint-commented-code: Whether collapsible if chains are linted if they contain comments inside the parts that would be collapsed.

    (default: false)