rust-lang / rust-lang/rustfmt

max_width not obeyed in match arm tuple

Open
#6,848 2 comments 0 reactions 1 assignee View on GitHub

@AsthaMishra is already working on this.

Since Sep 2, 2026.

A-matches C-bug I-max-width S-has-mcve X-impacts-stable-formatted-code X-impacts-stable-options
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.