Formatting match arm with a comment between the expression and the comma causes invalid code
Open
Nobody has claimed this yet.
A-comments
A-matches
C-bug
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Example code (playground link)
fn main() {
match 100 {
0 => println!("its zero")
// eprintln!("its zero")
,
_ => (),
}
}
After format with rustfmt 1.5.2-stable (90c5418 2023-05-31):
fn main() {
match 100 {
0 => println!("its zero"),
// eprintln!("its zero")
,
_ => (),
}
}
A comma is inserted after the println! call, causing this syntax error:
Compiling playground v0.0.1 (/playground)
error: expected pattern, found `,`
--> src/main.rs:5:9
|
5 | ,
| ^ expected pattern
error: could not compile `playground` (bin "playground") due to previous error
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 reproducing the playground example with rustfmt 1.5.2-stable and inspect the formatting path for match arms containing comments before a comma. Use the provided Rust snippet as the regression case; done means rustfmt no longer emits invalid Rust and the formatted result still compiles.
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
- Clearly specified
- Newbie friendliness
- 45/100