rust-lang / rust-lang/rustfmt

Formatting does not work with match arm having mixed OR clauses and comments

Open
#6,491 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments A-matches P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Related to #6060 and #6044. For the below snippet, rustfmt does nothing at all:

enum Foo {
    A,
    B,
    C,
    D,
}

fn main() {
    let foo = Foo::A;
    match foo {
        // Here is a comment
Foo::A |
    // And another one
        Foo::B |
        // Hey look! There's another one
    Foo::C |
// That's a lot of comments
        Foo::D => {}
    }
}

If someone more knowledgeable about rustfmt internals can please confirm that this is a solvable bug, I'd be happy to contribute the fix.

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 with the Rust snippet in the issue and run rustfmt on it to confirm that mixed OR-pattern clauses with comments remain unchanged. Trace the formatting path for match arms and comments, then verify that the example is formatted while preserving its comments and meaning.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.