rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Fix idempotency issue when wrapping the last match arm in a block

Open ytmimi opened this issue 3 years ago • 4 comments
trafficstars

Fixes #5193

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.

ytmimi avatar Jan 29 '22 23:01 ytmimi

@calebcartwright Two things to note:

  1. I plan on adding some additional tests cases to cover the various combinations of trailing_comma and match_block_trailing_comma. Just wanted to get the PR in when I identified an initial solution.

  2. I know you mentioned that #5193 might be a duplicate. If you happen to track down the original issue (or other duplicates), I'll see if this PR fixes them as well and add test cases accordingly!

ytmimi avatar Jan 29 '22 23:01 ytmimi

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 avatar Feb 07 '22 03:02 calebcartwright

@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!

ytmimi avatar Feb 07 '22 14:02 ytmimi

@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

ytmimi avatar Aug 09 '22 03:08 ytmimi