rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

rustfmt removes parenthesis in macro call

Open douglas-raillard-arm opened this issue 2 years ago • 2 comments

In the following snippet: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9b0e4357d4c32e40b179c243c6861f6c

macro_rules! mymacro {
    ($tt1:tt $(+ $tt2:tt)*) => {
        fn foo<F>(f: F) 
        where
            F: $tt1  $(+ $tt2)*
            {}
    }
}

mymacro!((for<'a> Fn()) + Send + Sync);

rustfmt removes paren in the following macro call:

mymacro!((for<'a> Fn()) + Send + Sync);

so that it gets turned into:

mymacro!(for<'a> Fn() + Send + Sync);

Unfortunately, the latter is not equivalent and does not compile

douglas-raillard-arm avatar Nov 09 '23 13:11 douglas-raillard-arm

Thanks for the report. In the more immediate term you may just want to change the call site delims to {} or [] to prevent this from occurring, or if you're using nightly, leverage the skip_macro_invocations option with my macro for the same

calebcartwright avatar Nov 09 '23 13:11 calebcartwright

@rustbot claim

rscprof avatar Jan 16 '24 19:01 rscprof