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

don't suggest erroneous trailing comma after .. #81103

Merged
merged 1 commit into from
Jan 19, 2021

Conversation

zackmdavis
Copy link
Member

In #76612, suggestions were added for missing fields in patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the last field. This resulted in the "if you don't care about missing fields" suggestion to recommend code with a trailing comma after the field ellipsis (..,), which is actually not legal (".. must be at the end and cannot have a trailing comma")!

Incidentally, the doc-comment on error_unmentioned_fields was using you_cant_use_this_field as an example field name (presumably copy-paste inherited from the description of Issue #76077), but the present author found this confusing, because unmentioned fields aren't necessarily unusable.

The suggested code in the diff this commit introduces to destructuring-assignment/struct_destructure_fail.stderr doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier _" thing), so you can't really call it a regression; it could be fixed in a separate PR.

Resolves #78511.

r? @davidtwco or @estebank

In rust-lang#76612, suggestions were added for missing fields in
patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the
last field. This resulted in the "if you don't care about missing
fields" suggestion to recommend code with a trailing comma after the
field ellipsis (`..,`), which is actually not legal ("`..` must be at
the end and cannot have a trailing comma")!

Incidentally, the doc-comment on `error_unmentioned_fields` was using
`you_cant_use_this_field` as an example field name (presumably
copy-paste inherited from the description of Issue rust-lang#76077), but
the present author found this confusing, because unmentioned fields
aren't necessarily unusable.

The suggested code in the diff this commit introduces to
`destructuring-assignment/struct_destructure_fail.stderr` doesn't
work, but it didn't work beforehand, either (because of the "found
reserved identifier `_`" thing), so you can't really call it a
regression; it could be fixed in a separate PR.

Resolves rust-lang#78511.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 17, 2021
@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 18, 2021

📌 Commit 14eb94f has been approved by davidtwco

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 18, 2021
Comment on lines +35 to 36
LL | Struct { a, b _ } = Struct { a: 1, b: 2 };
| ^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unapplicable suggestion now :-/

Copy link
Member

@davidtwco davidtwco Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From @zackmdavis's description:

The suggested code in the diff this commit introduces to destructuring-assignment/struct_destructure_fail.stderr doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier _" thing), so you can't really call it a regression; it could be fixed in a separate PR.

That seemed reasonable to me, I figured that this could be solved in a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! That's what I get for skip-reading.

@estebank
Copy link
Contributor

@bors r- to try and address the small regression I noticed.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 18, 2021
@estebank
Copy link
Contributor

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Jan 18, 2021

📌 Commit 14eb94f has been approved by davidtwco

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 18, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 18, 2021
don't suggest erroneous trailing comma after `..`

In rust-lang#76612, suggestions were added for missing fields in patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the last field. This resulted in the "if you don't care about missing fields" suggestion to recommend code with a trailing comma after the field ellipsis (`..,`), which is actually not legal ("`..` must be at the end and cannot have a trailing comma")!

Incidentally, the doc-comment on `error_unmentioned_fields` was using `you_cant_use_this_field` as an example field name (presumably copy-paste inherited from the description of Issue rust-lang#76077), but the present author found this confusing, because unmentioned fields aren't necessarily unusable.

The suggested code in the diff this commit introduces to `destructuring-assignment/struct_destructure_fail.stderr` doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier `_`" thing), so you can't really call it a regression; it could be fixed in a separate PR.

Resolves rust-lang#78511.

r? `@davidtwco` or `@estebank`
@bors
Copy link
Contributor

bors commented Jan 19, 2021

⌛ Testing commit 14eb94f with merge 94e6ea9...

@bors
Copy link
Contributor

bors commented Jan 19, 2021

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 94e6ea9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 19, 2021
@bors bors merged commit 94e6ea9 into rust-lang:master Jan 19, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 19, 2021
estebank added a commit to estebank/rust that referenced this pull request Jan 26, 2021
Account for parser recovered struct and tuple patterns to avoid invalid
suggestion.

Follow up to rust-lang#81103.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 28, 2021
…etrochenkov

Tweak suggestion for missing field in patterns

Account for parser recovered struct and tuple patterns to avoid invalid
suggestion.

Follow up to rust-lang#81103.
zaharidichev pushed a commit to zaharidichev/rust that referenced this pull request Mar 15, 2021
Account for parser recovered struct and tuple patterns to avoid invalid
suggestion.

Follow up to rust-lang#81103.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error suggestion for E0027 (pattern missing field) contains erroneous comma
6 participants