RS.CLIPPY.UNNESTED_OR_PATTERNS

Unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`

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

What it does

Checks for unnested or-patterns, e.g., Some(0) | Some(2) and suggests replacing the pattern with a nested one, Some(0 | 2).

Another way to think of this is that it rewrites patterns in disjunctive normal form (DNF) into conjunctive normal form (CNF).

Why is this bad?

In the example above, Some is repeated, which unnecessarily complicates the pattern.

Example

fn main() {
    if let Some(0) | Some(2) = Some(0) {}
}

Use instead:

fn main() {
    if let Some(0 | 2) = Some(0) {}
}

Configuration

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

    (default: current version)