rust-lang / rust-lang/rustfmt

Single expression match arm blocks on one line

Open
#5,766 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

i think there should be an option such that if a match arm is in a block but consists of a single expression, rustfmt keeps it on a single line. i.e.

match x {
    0 => { foo(); }
    1 => { bar(); }
    _ => { baz(); }
}

which, by default, gets formatted to

match x {
    0 => {
        foo(); 
    }
    1 => {
        bar(); 
    }
    _ => {
        baz(); 
    }
}

the reason for doing this being to throw away the result of foo(), bar(), and baz(), as if they returned different types, the match expression would cause a type error

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

No file or test is named in the issue. Start by reproducing the two match-formatting examples and tracing rustfmt's match-arm formatting and option handling. Done means an option controls single-expression block arms on one line, with coverage for arms whose expressions return different types.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.