-
Notifications
You must be signed in to change notification settings - Fork 888
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 stopped formatting const
items in macros
#6035
Comments
We haven't done a subtree sync since 2023-10-22 rust-lang/rust#117066 Running rustfmt built from source :rustfmt 1.7.0-nightly (bf96731 2024-01-20) cargo run --bin rustfmt <<< "m!(const N: usize = 0;);"
#output
m!(const N: usize = 0;); Running rustfmt +nightly-2023-10-22 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); Running rustfmt +nightly-2023-10-23 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); Running rustfmt +nightly-2023-10-24 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); Running rustfmt +nightly-2023-10-25 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); We've done 2 subtree pushes since the last release: #5980 and #5994. The last of which brought in changes from Not really sure what the issue is right now, but given that bors merged the last subtree sync on 2023-10-23 I'd assume that the error would have presented itself in the nightly-2023-10-24 release. Will try to look into this more a little later to figure out which nightly version started demonstrating this different macro formatting behavior. |
Tracked the issue down to the rustfmt +nightly-2023-12-27 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); rustfmt +nightly-2023-12-28 <<< "m!(const N: usize = 0;);"
m!(const N: usize = 0;); |
bisected the formatting changes back to rust-lang/rust#119099 |
This has to do with the weirdness of the way that rustfmt/src/parse/macros/mod.rs Line 54 in bf96731
Contrast this to the nonterminal parsing code, which first checks that the nonterminal may begin with a given token: In rust-lang/rust#119099, @fmease implemented a change so that This is okay for the purposes of macros, because he explicitly made sure that However, since rustfmt is not so careful about eagerly parsing macro args before checking that they're legal in macro position, this changed the way that the string of tokens is being parsed into macro args. I put up a fix against rust-lang/rust (since that should fix the nightly rustfmt): rust-lang/rust#120218. |
@compiler-errors thank you for the detailed explanation and for jumping into action so quickly on this one 🙏🏼 |
Just checked and rustfmt +nightly-2024-01-23 <<< "m!(const N: usize = 0;);"
m!(
const N: usize = 0;
); will hold off on closing this until the next subree push so that we incorporate the fix from rust-lang/rust back into rustfmt |
Test:
The text was updated successfully, but these errors were encountered: