Improvements to match formatting
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
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 anifguard).
(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 ofmatch_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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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