3

Fix missing struct field separators under certain conditions by cassaundra · Pul...

 2 years ago
source link: https://github.com/rust-lang/rustfmt/pull/5159
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Copy link

Contributor

@cassaundra cassaundra commented on Dec 29, 2021

edited

Fixes #4791 and #4928.

When struct_field_align_threshold is non-zero and trailing_comma is set to Never, struct field separators are omitted between field groups, resulting in invalid code. This issue is resolved by forcing separators between groups.

A test is included with a minimal reproducible example adapted from the original issue.

calebcartwright reacted with thumbs up emoji

@ytmimi if/when you get a chance could you take a look at this? At some point we had a different fix for this that can be found over on the 2.0 branch, so would like to compare this approach vs. that one. I also feel like you may have possibly done some somewhat similar work recently and thought you may be interested in reviewing

Copy link

Collaborator

ytmimi commented on Dec 30, 2021

Sure thing! I'll try to find the fix on the 2.0 branch to compare it to and will hopefully be able to get the review done in the next few days. I'll let you know if I run into any issues.

Copy link

Collaborator

ytmimi commented on Jan 2

I managed to track down #4201, which I believe is the PR that fixes this issue on the 2.0 branch. Both fixes are very similar and involve passing additional information to rewrite_aligned_items_inner. The previous PR passes a slice of the remaining fields to rewrite_aligned_items_inner, while the new proposal just passes a boolean. I happen to prefer the newer solution since it's a little more flexible in case there are other scenarios that we need to force trailing separators.

I'm happy with the changes as they are! @cassaundra If you have time would it be possible to add test cases with trailing_comma=Always and test cases where struct_field_align_threshold=0. Since these are the two configuration options that you need to reproduce the issue it would be great if we had test cases that fully covered their interaction in this scenario.

Copy link

Contributor

Author

cassaundra commented on Jan 3

Thank you for the review! I will add those test cases soon.

Copy link

Contributor

Author

cassaundra commented on Jan 15

edited

Apologies for the late response.

I've added the tests as requested, hopefully providing better coverage between struct_field_align_threshold and trailing_comma. The tests are located in tests/{source,target}/issue-4791/ and are named as follows:

zero non-zero

always (default) trailing_comma.rs

never no_trailing_comma.rs buggy.rs

Copy link

Collaborator

ytmimi commented on Jan 18

Thanks for adding those additional test cases! I think we now have the test coverage we need. @calebcartwright, is there anything else you'd like to see added? If not, I'm happy to move forward with these changes.

Copy link

Member

calebcartwright commented on Jan 29

Changes LGTM! @cassaundra would you mind adding test files for #4928 too?

Copy link

Contributor

Author

cassaundra commented 6 days ago

Sorry again for the late reply! It's been a crazy month. Those tests have now been added.

Copy link

Collaborator

ytmimi commented 5 days ago

@cassaundra Thanks for including that additional test!

Copy link

Member

@calebcartwright calebcartwright left a comment

Awesome, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Assignees

No one assigned

Labels
None yet
Projects

None yet

Milestone

No milestone

Linked issues

Successfully merging this pull request may close these issues.

3 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK