-
Notifications
You must be signed in to change notification settings - Fork 972
Fix idempotency issue when wrapping the last match arm in a block #5202
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
base: main
Are you sure you want to change the base?
Conversation
|
@calebcartwright Two things to note:
|
|
Changes LGTM @ytmimi, and happy to merge as-is. Will hold off on merging since it sounds like there may be more you want to do, but lmk when you're ready |
|
@calebcartwright Awesome! Yeah, I'd just want to add a few more test cases and see if I can track down any duplicates. I'll make sure to let you know when that's all taken care of! |
The issues was related to the interaction between two differnt configuration options when applied to the last match arm. * trailing_comma = Never * match_block_trailing_comma = true Previously, rustfmt only consider the ``match_block_trailing_comma`` configuration value when wrapping match arms. This lead to rustfmt adding a trailing comma to all newly wrapped match arms. Now, rustfmt also considers the ``trailing_comma`` configuration value when deciding whether or not to add a trailing comma when wrapping the last match arm in a block.
| FooBar::Baz => { | ||
| println!("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a little odd that trailing_comma=Never takes precedence over match_block_trailing_comma=true, for the last match arm but that's what I needed to do in order to prevent the idempotency issue since that's how arm_comma is implemented.
Lines 146 to 160 in a67d909
| fn arm_comma(config: &Config, body: &ast::Expr, is_last: bool) -> &'static str { | |
| if is_last && config.trailing_comma() == SeparatorTactic::Never { | |
| "" | |
| } else if config.match_block_trailing_comma() { | |
| "," | |
| } else if let ast::ExprKind::Block(ref block, _) = body.kind { | |
| if let ast::BlockCheckMode::Default = block.rules { | |
| "" | |
| } else { | |
| "," | |
| } | |
| } else { | |
| "," | |
| } | |
| } |
|
@calebcartwright no rush on this. I know it's been a while since you've last reviewed it. The last time you looked at these changes you said it was ready to merge, but since I've added some additional test cases I feel like it would be worth it to do another review if we choose to move forward with this |
Fixes #5193
The issues was related to the interaction between two differnt
configuration options when applied to the last match arm.
trailing_comma = Nevermatch_block_trailing_comma = truePreviously, rustfmt only consider the
match_block_trailing_commaconfiguration value when wrapping match arms. This lead to rustfmt
adding a trailing comma to all newly wrapped match arms.
Now, rustfmt also considers the
trailing_commaconfiguration valuewhen deciding whether or not to add a trailing comma when wrapping the
last match arm in a block.