Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt Macro with $( tt )* can introduce breaking comma #5654

Closed
JulianKnodt opened this issue Jan 8, 2023 · 1 comment
Closed

Rustfmt Macro with $( tt )* can introduce breaking comma #5654

JulianKnodt opened this issue Jan 8, 2023 · 1 comment

Comments

@JulianKnodt
Copy link
Contributor

JulianKnodt commented Jan 8, 2023

Without running rustfmt, this macro compiles (albeit it does look very strange).
After running rustfmt, it introduces a comma between functions which leads to it no longer compiling.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0d69aa8f44c299d2726f3e39e6c535ff

Inlined:

macro_rules! document {
  ($t: ty, $( $code_block: tt )*)=> {
    const DOC: &'static str = stringify!($( $code_block )*);

    $( $code_block )*
  }
}
struct T;

document!(T, fn example() {} fn other() {});
// ^ Comma is introduced here: `fn example() {}, fn other() {}`

fn main() {}
@JulianKnodt JulianKnodt changed the title Rustfmt Macro introduces breaking comma Rustfmt Macro with $( tt )* can introduce breaking comma Jan 8, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Jan 8, 2023

Thanks for reaching out. I believe this is a duplicate of #4375 and #4631

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants