Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt deletes comment beside macro identifier #6484

Open
jaybosamiya opened this issue Feb 24, 2025 · 1 comment
Open

rustfmt deletes comment beside macro identifier #6484

jaybosamiya opened this issue Feb 24, 2025 · 1 comment

Comments

@jaybosamiya
Copy link

jaybosamiya commented Feb 24, 2025

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.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 24, 2025

Thanks. Yeah, rustfmt isn't expecting to find a comment between the macro's name println, and the !. My recommendation would be not to put your comment there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants