rust-lang / rust-lang/rustfmt

`match` indentation broken for tuple-closing brackets

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

Nobody has claimed this yet.

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

Description

The following snippet is formatted using rustfmt.

match Some(1) {
    Some(number) => (
        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        number,
    )
        .to_owned(),
    None => ("test", 0).to_owned(),
};

In my opinion, this is not very readable since it breaks the strict indentation of anything inside a match arm. Shouldn't the closing bracket of the tuple in the Some(_) arm be indented further (and therefore, potentially, the two fields of the tuple as well)?

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 provided match-arm and tuple-formatting snippet with rustfmt, then trace the formatter entry point handling match arms and tuple expressions. Done means the tuple-closing bracket and its fields follow the intended match-arm indentation, with a regression test covering the example.

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
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.