Skip to content
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

Rustfmt duplicates commas in struct declarations #4714

Closed
xTibor opened this issue Feb 22, 2021 · 4 comments
Closed

Rustfmt duplicates commas in struct declarations #4714

xTibor opened this issue Feb 22, 2021 · 4 comments
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-comments bug Panic, non-idempotency, invalid code, etc.

Comments

@xTibor
Copy link

xTibor commented Feb 22, 2021

Describe the bug

There's a weird interaction between comments and commas in struct declarations that leads to duplication of commas and breaking the syntax of the formatted code (error: expected identifier, found ',')

To Reproduce

Input:

struct Something {
    field: u32/*a*/,/*b*/
}

Formatting result:

struct Something {
    field: u32, /*a*/,/*b*/
}

Expected behavior

Do not duplicate commas.

Meta

  • rustfmt version: 1.4.36-nightly (2021-02-07 7de6968)
  • From where did you install rustfmt?: playground
  • How do you run rustfmt: playground
@xTibor xTibor added the bug Panic, non-idempotency, invalid code, etc. label Feb 22, 2021
@xTibor
Copy link
Author

xTibor commented Feb 22, 2021

Just noticed there's a similar issue at #3876. My repro is in a different context than discussed there, however if the root cause is the same this issue can be closed as a dupe.

whizsid added a commit to whizsid/rustfmt that referenced this issue Feb 22, 2021
@whizsid
Copy link
Contributor

whizsid commented Feb 22, 2021

@xTibor Yes it was a duplicate and #4520 will fix it.

@calebcartwright
Copy link
Member

Thanks for the report @xTibor and @whizsid for pulling this in as a test case on #4520 👍

@calebcartwright calebcartwright added a-comments 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release labels Feb 24, 2021
calebcartwright pushed a commit that referenced this issue Feb 27, 2021
#4520)

* Fixed Issue 'Trailing comma is duplicated when obstructed by comments'

* Put separator at the begining of the post comment

* Removed accidentally pushed tmp file

* Add test cases for #4714

* Avoid ownership issue by a tricky way and added test cases for block comments

* Fixed tests
@calebcartwright
Copy link
Member

Resolved via 74768b7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-comments bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

3 participants