rust-lang / rust-lang/rustfmt

rustfmt misformat when comment blocks are used

Open
#6,426 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments C-bug I-invalid-code only-with-option UO-wrap_comments
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.