rustfmt removes comment in macro invocation
Open
Nobody has claimed this yet.
A-comments
A-macros
P-low
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
rustfmt will remove the comment in the following macro invocation:
macro_rules! add_my_field {
{
$(#[$m:meta])*
$v:vis struct $name:ident {
$($var_v:vis $var_name:ident: $var_ty:ty,)*
}
} => {
$(#[$m])*
$v struct $name {
$($var_v $var_name: $var_ty,)*
my_field: u32,
}
}
}
add_my_field!(
#[derive(Debug)]
struct MyStruct {
a: u8,
b: u16,
}
// this comment will be deleted (it doesn't matter if it's // or /* */)
);
fn main() {
println!("{:#?}", MyStruct {
a: 1,
b: 2,
my_field: 3,
})
}
Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c452814ae6ed3ad5042af833d1e0b359
Tested with:
- rustfmt 1.5.1-stable (fc594f15 2023-01-24)
- rustfmt 1.5.2-nightly (2023-02-16 9a7cc6c)
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 using the macro invocation and compiler versions shown in the report, confirming that the comment is removed. Trace rustfmt's handling of comments inside macro invocations, then add a regression test for this example. Done means formatting preserves the comment, including both line and block comment forms.
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
- Clearly specified
- Newbie friendliness
- 48/100