rust-lang / rust-lang/rustfmt

rustfmt requires two runs to converge on contrived input

Open
#6,437 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-non-idempotency
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

fn test(input: Foo) {
    match input {
        Foo::Bar => {
            ;
            Baz {
                field: 0
            }
        }
    }
}

Given this admittedly contrived input, running rustfmt once removes the semicolon. Running it a second time removes the braces for the match body.

I don't know if rustfmt has a rule about being idempotent, but it certainly would surprise me to regularly encounter situations where I have to manually run it to a fixed point.

Tested in the playground, 1.8.0-stable (2024-11-26 90b35a6239).

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 supplied Rust input with rustfmt and comparing the first and second outputs. Trace the formatter handling for match arms, semicolon removal, and brace removal; done means formatting reaches the same result in one run while preserving valid Rust formatting behavior.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.