match with one arm whose pattern only binds a name

ID

rust.maintainability.match_single_binding

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Control Flow

Language

Rust

Description

Reports a match with a single arm whose pattern is a plain binding, a _, or a tuple of bindings. Nothing is being discriminated - the arm always runs - so the construct is a let written as control flow.

Rationale

A match tells the reader that a value is being discriminated and that the arms are the alternatives worth considering. When there is one arm and its pattern matches everything, that promise is false: the reader stops to work out which cases are covered, and the body sits one indentation level deeper than it needs to for no gain.

The following code illustrates the pattern detected by this rule:

pub fn binding_arm(x: i32) {
    // FLAGGED: match with one arm whose pattern only binds a name
    match x {
        y => println!("{}", y),
    }
}

Remediation

Bind with let and drop the construct - match x { y ⇒ body } becomes let y = x; followed by the body, and the tuple form becomes let (left, right) = p;. When the value is not used at all, drop the binding and keep only the body.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved