Skip to content

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

@Marsman1996

Description

@Marsman1996

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsA-trait-boundsArea: trait boundsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-invalid-codeIssue: formatting causes compile-pass code to compile-fail

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions