rust-lang / rust-lang/rustfmt

Alternative option for `match_arm_leading_pipes`?

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

Nobody has claimed this yet.

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

Description

I would really like an option for match_arm_leading_pipes which only forces matches to the same branch onto new lines with a pipe. For example:

match foo {
    aaa => ()
    bbb | ccc | ddd => ()
    eee => ()
} 

becomes

match foo {
    aaa => ()
    bbb
    | ccc 
    | ddd => ()
    eee => ()
} 

I personally like this change because it prevents overly-cramped long multi-match arms while also making it clear which "blocks" correspond to which arms. Is this possible already? If not, could someone point me in the right direction for adding a PR?

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 tracing the existing match_arm_leading_pipes configuration and the formatter logic that handles multi-pattern match arms. Compare its current output with the requested example, then determine how an alternative option should be represented and tested. Done means the option produces the requested line breaks and preserves existing behavior when disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
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.