rust-lang / rust-lang/rustfmt

Formatter takes two runs to fully format comment after match arm

Open
#4,757 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Input

fn main() {
    match 1 {
        _ => {},
        // hello!
    }
}

Output

fn main() {
    match 1 {
        _ => {}
        // hello!
    }
}

Expected output

fn main() {
    match 1 {
        _ => {} // hello!
    }
}

You get the expected output if you run it a second time. This means that the formatter needs multiple runs to fully finish formatting the code. That does not seem right. I want to be able to trust the formatter in that it will do it all in one run so that I never get into the habit of running it twice each time just to be 100% sure. Therefore I report this as a bug.

Meta

  • rustfmt version: rustfmt 1.4.30-stable (8c6769d 2021-01-18)
  • From where did you install rustfmt?: rustup

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 match-arm example with the listed rustfmt version, then trace the formatter's handling of comments after match arms. Done means one formatting run produces the expected output and a regression test covers the example.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.