Comma gets duplicated when obstructed by inline comments
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Input:
fn foo() {
struct A {
a: i32 /* i32 */, /* type */
}
let a = A {
a: 123 /* default */, /* value */
};
let b = match () {
() => 123 /* some */, /* comment */
};
match todo!() {
Ok(0) => break /* EOF */,
Ok(r) => read += r,
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) => return Err(e),
}
}
// https://github.com/rust-lang/rustfmt/issues/3876#issuecomment-619383696
fn f<S>(s: S)
where
S: Send /* */,
//
{
}
Output:
fn foo() {
struct A {
a: i32, /* i32 */, /* type */
}
let a = A {
a: 123, /* default */, /* value */
};
let b = match () {
() => 123, /* some */, /* comment */
};
match todo!() {
Ok(0) => break, /* EOF */,
Ok(r) => read += r,
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) => return Err(e),
}
}
// https://github.com/rust-lang/rustfmt/issues/3876#issuecomment-619383696
fn f<S>(s: S)
where
S: Send, /* */,
//
{
}
Note the difference on /* */ lines! An unexpected comma was added.
Expected:
Might be something like a: i32, /* i32 */ /* type */ or Ok(0) => break, /* EOF */? By the code style convention comma gets moved (but not unexpectedly duplicated) before the inline comments.
Maybe an uncovered case or regression of #3876? I took the example in https://github.com/rust-lang/rustfmt/issues/3876#issuecomment-619383696 - also reproducible using the current rustfmt tool.
Version
❯ cargo run --bin rustfmt -- --version
rustfmt 1.8.0-nightly (86261bfb87 2025-12-08)
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 examples with cargo run --bin rustfmt -- --version and the supplied Rust input. Trace how rustfmt handles commas adjacent to inline comments, then add coverage for the shown cases and confirm formatting moves commas without duplicating them.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100