-
Notifications
You must be signed in to change notification settings - Fork 895
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
Always Place Spaces after Commas in Macro Match Arms #5574
base: master
Are you sure you want to change the base?
Always Place Spaces after Commas in Macro Match Arms #5574
Conversation
overall I think the change looks good. I'm curios how the following is formatted: macro_rules! x {
($a:ident, $b:ident,) => {};
} Do we add a space after the trailing comma? Does it make sense to do so? |
Personally, I think it looks better without a space between the trailing comma and parenthesis.
Nope. In fact we remove it if it's present, although this seems like it was already true before my PR. macro_rules! x {
($a:ident, $b:ident,) => {}; // Unchanged
- ($a:ident, $b:ident, ) => {}; // Removes the space
+ ($a:ident, $b:ident,) => {};
} The macro-args-parser parses the stuff between the parenthesis separately (with a new parser): Lines 913 to 915 in e041c20
|
I appreciate you looking into this for me. I just wanted to double check that was the case since it would have been unfortunate if we added a space after the trailing comma. I'm not sure if there is a test case with a trailing comma, but if there isn't would you mind adding one, thanks! |
Absolutely! Honestly, I hadn't even considered that edge case, so it's good you thought it up!
Just added one! I think you're right, we should totally have that anyways, regardless of this PR. Since the commit for the extra test is unrelated to these changes, it feels cleaner to keep the commits separate. |
Thanks for including the additional test case. Before I forget, I also want to say thanks for your first contribution to rustfmt 🎉
Sure, we'll figure that out once upstream stuff has been sorted out and we're ready to merge. Just as a side note, rustfmt's goal is to be an implementation of The Rust Style Guide. The section on The rustfmt team tries not to make style determinations ourselves so we may also need to add some additional detail to the guide before moving forward. @calebcartwright what are your thoughts? Can we move forward without an addition to the guide? The only place in the guide where I found some discussion on commas between metavariables were the last few comments on rust-lang/style-team#121, but that discussion hasn't been active for a very long time. Barring a potential addition to the style guide I think we're good to go here! |
Thanks! And right back at you for putting so much effort into maintaining it!
Totally cool. Just let me know if there's anything else you want me to do!
"quite sparse", you really aren't kidding!! I only opened this PR because the macro formatting logic already exists, and my coworkers opted-into it |
Alsooo, while I have your attention ^-^ do you have any opinion on: #3354 (comment)? I pro-actively offered to fix the problem he was describing, but after thinking about it more, now I'm not completely sure if it's sane to always remove spaces after |
@calebcartwright would know more about whether or not a style guide amendment is needed before we can move forward here. Yeah macros are tricky since they can contain any valid tokens that might not necessarily be valid rust syntax, while rustfmt is primarily designed to format valid rust syntax. When macros introduce invalid syntax that's when rustfmt struggles to format them.
I think it's great that your coworkers are playing around with unstable options, and feedback on their behavior is always appreciated! If I've learned anything from working on the project it's that developers are very passionate about their formatting preferences. I don't think we'll ever get to a point where everyone is 100% satisfied by rustfmts output 😅 |
I can't say I've spent a lot of time thinking about wether or not there should be whitespace around |
41aac15
to
174b7a0
Compare
@InsertCreativityHere I think this may fix the single-line issue I mentioned in #5984, but do you know if it may also fix the multiline issue? |
@ytmimi can this merge as-is? I think a change for |
@tgross35 I looked into this and this seems to resolve the single-line issue you brought up in #5984, but this doesn't resolve the multi-line case. When I've got some time I'll try to dig into what's going on there. input: macro_rules! foo {
(foo: $foo:ident,bar: $bar:ident,baz: $baz:ident,qux: $qux:ident,) => {};
} output: macro_rules! foo {
(foo: $foo:ident, bar: $bar:ident, baz: $baz:ident, qux: $qux:ident,) => {};
}
I think so. I'd still like to discuss this with Caleb and see if he has any reservations, but I'm in favor of moving forward. |
As @ytmimi points out, my fix was pretty specific, only for commas!
I'll update my PR to be up-to-date with main over the weekend too. My coworkers religiously remove |
@InsertCreativityHere we try to avoid merge commits if possible. When you have a second can you rebase your changes instead? |
b6a8d58
to
bc64185
Compare
@ytmimi For sure! I just rebased my commits over master. |
This PR fixes #5573 by ensuring a space is always placed after commas in macro match arms,
and updates a test that exhibited the mistake.