rustfmt deletes comment beside macro identifier
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the x.rs example and run rustfmt --check to confirm that the comment between println and ! is removed. Trace rustfmt's handling of comments around macro identifiers; done means formatting preserves the comment and the check reports no unwanted deletion.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100