Two-arm match whose second arm does nothing

ID

rust.maintainability.single_match

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Control Flow

Language

Rust

Description

Reports a match with two arms where the second one is _ ⇒ (), _ ⇒ {}, None ⇒ () or None ⇒ {}, so only one arm carries behaviour. That is a conditional binding, which if let expresses directly.

Rationale

A match invites the reader to compare its arms, and here there is nothing to compare - the do-nothing arm exists only to satisfy exhaustiveness. It also costs four lines and a level of indentation for a single conditional, and an empty arm is easy to misread as an oversight rather than a deliberate no-op.

The following code illustrates the pattern detected by this rule:

pub fn wildcard_unit(o: Option<i32>) {
    // FLAGGED: Two-arm match whose second arm does nothing
    match o {
        Some(v) => println!("{}", v),
        _ => (),
    }
}

Remediation

Use if let: match o { Some(v) ⇒ body, _ ⇒ () } becomes if let Some(v) = o { body }. When the do-nothing case is the interesting one, let …​ else or if let …​ else keeps the happy path unindented.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved