rust-lang / rust-lang/rustfmt

Error formatting with block comment after match scrutinee

Open
#6,663 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

I am getting error[internal]: left behind trailing whitespace on the latest stable 1.90 and nightly rustc 1.92.0-nightly (4645a7988 2025-09-17)

Minimum example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=67d8495779f0d47760dff7bea024ad75

fn main() {
    match () /*x*/ {
     
        _ => {}
    }
}

The issue is caused by the comment after the scrutinee. If you remove the x (but keep the /**/), it will format, or if you replace x with any number of spaces, it formats fine.

Also fails if scrutinee is a variable name.

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

Run the linked Rust Playground example with rustfmt and confirm the trailing-whitespace error for a block comment after the match scrutinee. Compare it with the reported variants using /**/ or spaces, then trace the formatting path for match scrutinees and comments. Done means the example formats successfully without the internal error while preserving the comment.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.