Skip to content

rustfmt deletes comment beside macro identifier #6484

Open
@jaybosamiya

Description

@jaybosamiya

Rust allows placing comments inside macro names between the macro identifier and the exclamation/bang (playground link)

This comment is gobbled by rustfmt:

$ cat x.rs
fn main() {
    println/*test*/!("hi");
}

$ rustc x.rs && ./x
hi

$ rustfmt --check x.rs
Diff in /tmp/x.rs:1:
 fn main() {
-    println/*test*/!("hi");
+    println!("hi");
 }

$ rustc --version && rustfmt --version
rustc 1.85.0 (4d91de4e4 2025-02-17)
rustfmt 1.8.0-stable (4d91de4e48 2025-02-17)

Admittedly, this is a silly case and I don't expect anyone to actually be using this "feature" of Rust, but I thought I should document this low-priority issue that I found a little funny.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions