-
Notifications
You must be signed in to change notification settings - Fork 879
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
Regression (poor-formatting) in macros formatting since 1.50 #5419
Comments
Thanks for the report. I'm not entirely sure that 1.50 introduced this change. I just checked using fn main() {
format_me_wrong!(
bool | _, _ | {
true;
true;
}
);
} Also checked |
That is kinda strange, that's my results
|
I'd seen this but hadn't had a chance to respond yet. My assumption was that @maxwase was referring to the Rust 1.50 release and the version of rustfmt that shipped with it, not the recent rustfmt version from a couple weeks ago (rustfmt is versioned independently of the compiler). I also suspect that this is not a regression at all, but is simply reflective of the limits of formatting args to macro calls, and that if one were to go back to rust 1.49 you'd discover rustfmt actually isn't formatting the call at all (which can be tested by modifying the input to be highly misformatted which should be left as-is by rustfmt). For context, rustfmt is a formatter of Rust syntax. Args to macro calls aren't always valid Rust syntax strictly speaking. In order to support the desire of our users for rustfmt to provide some formatting for calls, rustfmt will attempt to see if args can be parsed as valid rust syntax, and if they can, then rustfmt applies the corresponding rules. In some cases, args to calls can actually be parsed as valid syntax, but that's not actually what was intended. In this case, those args can be parsed as binary expressions and are formatted as such. The change you see from 1.49 to 1.50 is simply due to the compiler's parsing being enhanced to be able to handle that sequence of tokens in a way that allow for successful parsing-as-an-expression, so rustfmt 1.4.25/rust 1.50 was the first version where rustfmt was actually able to format that call. This isn't a regression, and isn't going to change. As such if you'd like different formatting your options are to change the call delimiters to |
Oh, thanks! |
I should also add that if you don't want to change the delimiters, then the only way to currently skip would be via attributes applied on each call (https://github.com/rust-lang/rustfmt#tips). However, we will also be adding a new configuration option in an upcoming release (#5347) which will allow you to designate macro calls to be skipped for formatting from one place in your config file |
Since 1.50 the following macros:
formats like this:
instead of this:
The key part is to have a literal before "closure" and 2+ lines after "closure"
The text was updated successfully, but these errors were encountered: