Skip to content

max_width not obeyed in match arm tuple #6848

@warrd

Description

@warrd

Summary

rustfmt reformats a multi-line tuple pattern in a match arm into a single
line that exceeds max_width = 80.

I tried to format this code:

#[derive(Clone, Copy)]
enum ExampleTypeX {
    VariantAlphaSampleXYZ,
    VariantBetaXYZ,
}

fn demo(lhs: ExampleTypeX, rhs: ExampleTypeX) {
    match (lhs, rhs) {
        (
            ExampleTypeX::VariantAlphaSampleXYZ,
            ExampleTypeX::VariantBetaXYZ,
        ) => unsafe {
        }
        _ => {}
    }
}

fn main() {}

Expected behavior

rustfmt should preserve the multi-line tuple pattern, or otherwise format the
arm so that it does not exceed max_width = 80.

Actual behavior

rustfmt rewrites it to:

fn demo(lhs: ExampleTypeX, rhs: ExampleTypeX) {
    match (lhs, rhs) {
        (ExampleTypeX::VariantAlphaSampleXYZ, ExampleTypeX::VariantBetaXYZ) => unsafe {
        },
        _ => {}
    }
}

The formatted match arm is 87 columns wide, exceeding max_width = 80.

Configuration

rustfmt.toml:

max_width = 80

Reproduction Steps

  1. Create a Rust file with the example above.

  2. Create a rustfmt.toml containing:

    max_width = 80
  3. Run cargo fmt (or rustfmt on the file).

  4. Observe that the tuple pattern in the match arm is collapsed to one line.

  5. Observe that the resulting line exceeds max_width.

Meta

rustfmt 1.8.0-stable (ed61e7d7e2 2025-11-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-matchesArea: match arms, patterns, blocks, etcC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEF-impacts-stable-formatted-codeExpected formatting impact: affects stable formatted code (caution)F-impacts-stable-optionsExpected formatting impact: impacts stable options (caution)I-max-widthIssue: formatting exceeds maximum widthS-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions