rustfmt attribute to keep match clauses sorted and merged
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
When writing some long matches that map one kind of value to another, it can be extremely helpful to keep the clauses in alphabetically sorted order, as well as merging multiple mappings to the same value.
I'd love to have a rustfmt attribute, along the lines of #[rustfmt::sorted], which when applied to a match would cause rustfmt to keep the clauses sorted and merged.
By making this a dedicated attribute, it can't affect code unless someone opts into it, and by opting in, the user is explicitly stating that the order doesn't semantically matter. Thus, rustfmt doesn't have to prove that sorting doesn't change the meaning of the code; it can rely on the user for that.
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
The issue names no files, tests, or entry points. Start by locating rustfmt's handling of custom attributes and match-expression formatting, then determine how sorted and merged clauses would be specified and validated; done means an opt-in attribute produces the requested ordering without affecting unannotated matches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100