Skip to content

Comment in empty generic arg in macro context is unexpectedly removed #7182

Open

Description

@jieyouxu

Summary

Follow-up to #7181.

I tried to format this code:

macro_rules! m { ($f:ident </*c*/>) => {} }
fn main() {
    m!(Foo</*c*/>);
}

Expected behavior

I expected to see this happen: keep the comment in the empty generic arg.

Actual behavior

Instead, this happened: comment is removed.

Diff in /Users/joe.xu/Documents/repos/repro/foo.rs:2:
     ($f:ident </*c*/>) => {};
 }
 fn main() {
-    m!(Foo</*c*/>);
+    m!(Foo<>);
 }

Configuration

rustfmt after #7181 applied.

Reproduction Steps

Just run on the file.

Meta

rustfmt after #7181 applied.

Activity

  1. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)
    I-unexpectedly-removes-codeIssue: unexpectedly removes code that we should not be removing
    on Oct 14, 2026
  2. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Oct 14, 2026
  3. removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Oct 14, 2026
  4. changed the title [-]Comment in empty generic arg in macro context is unexpectedtly removed[/-] [+]Comment in empty generic arg in macro context is unexpectedly removed[/+] on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsA-genericsArea: genericsA-macrosArea: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-unexpectedly-removes-codeIssue: unexpectedly removes code that we should not be removing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions