RS.CLIPPY.ELSE_IF_WITHOUT_ELSE

`if` expression with an `else if`, but without a final `else` branch

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

What it does

Checks for usage of if expressions with an else if branch, but without a final else branch.

Why restrict this?

Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10).

Example

if x.is_positive() {
    a();
} else if x.is_negative() {
    b();
}

Use instead:

if x.is_positive() {
    a();
} else if x.is_negative() {
    b();
} else {
    // We don\'t care about zero.
}