rust-lang / rustfmt

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

`for<>` is erased from macro calls #5316

Open WaffleLapkin opened 2 years ago

WaffleLapkin commented 2 years ago

Given this input:

a!(for<> A);
a!(for<A> A);
a!(for<A: A> A);
a!(for<A: ?A> A);

rustfmt produces the following output:

a!(A);
a!(A);
a!(A);
a!(A);

Which is incorrect since macros can depend on the for<...>. (playground)

ytmimi commented 2 years ago

Thanks for the report!

Seems like this could be related to #4631 as both deal with dropping tokens in macro calls.

EDIT: upon further investigation these issues don't seem to be related. #4631 deals more with adding tokens to macro calls. specifically adding commas ,.

ytmimi commented 2 years ago

I wonder if the advice from https://github.com/rust-lang/rustfmt/issues/4631#issuecomment-760640022 would help? I know that rustfmt doesn't typically format macros that use {}.

ytmimi commented 2 years ago

Doing some testing and it seems like #5301 will fix some of the examples you outlined, but the first case a!(for<> A); is still an issue even after testing this snippet on that branch.

ytmimi commented 1 year ago

I believe all but the first issue were resolved by #5848. @compiler-errors do you have any interest in digging into the empty for<> case?