rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

rustfmt breaks macros involving $

Open stephanemagnenat opened this issue 1 year ago • 2 comments

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 avatar Sep 08 '23 16:09 stephanemagnenat

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

stephanemagnenat avatar Sep 09 '23 07:09 stephanemagnenat

@rustbot claim

rscprof avatar Jan 17 '24 17:01 rscprof