rust-lang / rust-lang/rustfmt

Match arm pattern formatting exceeds the maximum line length

Open
#6,697 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-matches I-max-width SO-max_width
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Formatting the following code

impl Foo {
    fn foo() {
        loop {
            match (pat, self.next_token.kind) {
                (_, TokenKind::Whitespace)
                | (Pat::AnyComment, TokenKind::BlockComment { terminated: true, .. } | TokenKind::LineComment { .. }) => {
                    self.step()
                },
            }
        }
    }
}

Results in:

error[internal]: line formatted, but exceeded maximum width (maximum: 120 (see `max_width` option), found: 122)
   --> \\?\F:\rust-clippy-jj\clippy_dev\src\parse\cursor.rs:104:104:121
    |
104 |                 | (Pat::AnyComment, TokenKind::BlockComment { terminated: true, .. } | TokenKind::LineComment { .. }) => {
    |                                                                                                                         ^^
    |

Config is:

max_width = 120
error_on_line_overflow = true

Making the offending line one character longer causes it to be correctly formatted across multiple lines.

Version:

rustfmt 1.8.0-nightly (4645a79881 2025-09-17)

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.

Research direction

Start by reproducing the example with max_width = 120 and error_on_line_overflow = true using the reported rustfmt nightly version. Trace the match-arm formatting and line-breaking logic for the pattern shown in clippy_dev/src/parse/cursor.rs:104. Done means the example is split across lines without exceeding 120 columns or reporting an internal overflow error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.