RS.CLIPPY.REDUNDANT_GUARDS

Checks for unnecessary guards in match expressions

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

What it does

Checks for unnecessary guards in match expressions.

Why is this bad?

It's more complex and much less readable. Making it part of the pattern can improve exhaustiveness checking as well.

Example

match x {
    Some(x) if matches!(x, Some(1)) => ..,
    Some(x) if x == Some(2) => ..,
    _ => todo!(),
}

Use instead:

match x {
    Some(Some(1)) => ..,
    Some(Some(2)) => ..,
    _ => todo!(),
}