rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.07k stars 893 forks source link

rustfmt breaks macros involving $ #5905

Open stephanemagnenat opened 1 year ago

stephanemagnenat commented 1 year ago

This macro:

macro_rules! test_macro {
    ($member:ident $($rest:tt)*) => {
        paste::paste! {fn test(&self) {
        (self.$member$($rest)* )
        }}
    };
}

gets wrongly reformatted as:

macro_rules! test_macro {
    ($member:ident $($rest:tt)*) => {
        paste::paste! {fn test(&self) {
        (self.$$member($rest)* )
        }}
    };
}

The diff being:

4c4
<         (self.$member$($rest)* )
---
>         (self.$$member($rest)* )

The version being: rustfmt 1.6.0-stable (5680fa1 2023-08-23)

stephanemagnenat commented 1 year ago

Note that if there is a space after the first argument: self.$member $($rest)* then rustfmt doesn't produce the erroneous output.

rscprof commented 10 months ago

@rustbot claim