rust-lang / rust-lang/rust

Improvements to match formatting

Open
#152,763 27 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

disposition-merge finished-final-comment-period I-lang-radar T-style
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

View all comments

As originally discussed and described in https://github.com/rust-lang/style-team/issues/196#issuecomment-2810856708, we want to do the following:

  • We want to say that whenever we wrap the { to a new line, we always put the => on the same line as the { rather than hanging it on the end of the previous line. In other words, "never break between the => and the {".
  • We want to break the => { onto a new line if the pattern spans multiple lines and has indented continuation lines (because it has an if guard).

(2026-03-03:) Originally, there was a third rule proposed:

  • We want to always break a match arm body onto a new line if the pattern spans multiple lines (and thus always use braces for such a match arm, given the default setting of match_arm_blocks).

In https://github.com/rust-lang/rust/issues/152763#issuecomment-3992508472, we decided not to do this one as part of this proposal.

cc @rust-lang/style

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 locating rustfmt's match-arm formatting entry point and existing tests for match formatting. Implement the two agreed rules for => { placement, while leaving the rejected third rule unchanged. Done means coverage demonstrates the required wrapping behavior for multiline patterns and if guards.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.