rust-lang / rust-lang/rustfmt

rustfmt rewrites valid `impl<T: /*comment*/>` into invalid syntax with `,,`

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

Nobody has claimed this yet.

A-comments A-trait-bounds C-bug I-invalid-code
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Summary

I tried to format this code:

trait SpinGuardian {}

struct RwLockUpgradeableGuard<'a, T, G: SpinGuardian>(&'a T, G);

// Compile fail after rustfmt
impl<T: /*?Sized*/, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}
Expected behavior

I expected the formated code to be compiled normally.

Actual behavior

Instead, this happened:

trait SpinGuardian {}

struct RwLockUpgradeableGuard<'a, T, G: SpinGuardian>(&'a T, G);

// Compile fail after rustfmt
impl<T /*?Sized*/,, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}

And I get a compile error:

error: expected one of `#`, `>`, `const`, identifier, or lifetime, found `,`
 --> /playground/src/main.rs:6:19
  |
6 | impl<T /*?Sized*/,, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}
  |                   ^ expected one of `#`, `>`, `const`, identifier, or lifetime

Configuration

No extra configuration.

Reproduction Steps

Just run rustfmt and then compile.

You can reproduce this in the Rust Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=358af121c5c0572cf0663c013de3948e

Meta

rustfmt --version:

rustfmt 1.9.0-nightly (562dee4820 2026-03-21)

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

Start by running rustfmt on the Rust Playground reproducer and comparing the input with the invalid formatted output. Trace the rustfmt handling of comments in generic bounds, then add regression coverage showing that the formatted impl remains valid Rust and no longer produces the extra comma.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.