RS.CLIPPY.MATCH_LIKE_MATCHES_MACRO

A match that could be written with the matches! macro

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

What it does

Checks for match or if let expressions producing a bool that could be written using matches!

Why is this bad?

Readability and needless complexity.

Known problems

This lint falsely triggers, if there are arms with cfg attributes that remove an arm evaluating to false.

Example

let x = Some(5);

let a = match x {
    Some(0) => true,
    _ => false,
};

let a = if let Some(0) = x {
    true
} else {
    false
};

Use instead:

let x = Some(5);
let a = matches!(x, Some(0));

Configuration

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

    (default: current version)