rustfmt misformat when comment blocks are used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
misformat if two consecutive lines start with /* and the first line only contains comments and no actual code.
rustfmt doesn't correctly parse the end (*/) of /* code blocks. I use a code block to better see the offsets of each field of a type. Unfortunately this causes the second line /* to be changed to just * as if it is a continued comment line.
It only happens if the line starts with /* and has only comments in this line.
.rustfmt.toml:
wrap_comments = true
Input:
pub struct Type {
/* 0x34 */ // _buf2: Buf<0x4>, // padding
/* 0x4C */ pub field: u32,
}
Output:
pub struct Type {
/* 0x34 */ // _buf2: Buf<0x4>, // padding
* 0x4C */ pub field: u32,
}
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
Reproduce the issue using the shown .rustfmt.toml with wrap_comments enabled and the provided Rust struct input. Trace rustfmt's handling of consecutive /* comment lines, then add a regression test showing that the second comment marker is preserved and the formatted output remains valid.
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
- 45/100