RS.CLIPPY.COLLAPSIBLE_MATCH

Nested `match` or `if let` expressions where the patterns may be \"collapsed\" together.

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

What it does

Finds nested match or if let expressions where the patterns may be "collapsed" together without adding any branches.

Note that this lint is not intended to find all cases where nested match patterns can be merged, but only cases where merging would most likely make the code more readable.

Why is this bad?

It is unnecessarily verbose and complex.

Example

fn func(opt: Option<Result<u64, String>>) {
    let n = match opt {
        Some(n) => match n {
            Ok(n) => n,
            _ => return,
        }
        None => return,
    };
}

Use instead:

fn func(opt: Option<Result<u64, String>>) {
    let n = match opt {
        Some(Ok(n)) => n,
        _ => return,
    };
}

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)