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

Recover missing comma after match arm #97823

Merged
merged 1 commit into from
Jun 8, 2022

Conversation

compiler-errors
Copy link
Member

If we're missing a comma after a match arm expression, try parsing another pattern and a following =>. If we find both of those, then recover by suggesting to insert a ,.

Fixes #80112

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 7, 2022
@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 7, 2022
@compiler-errors
Copy link
Member Author

r? rust-lang/diagnostics

@rust-highfive rust-highfive assigned estebank and unassigned jackh726 Jun 7, 2022
arrow_span,
"while parsing the `match` arm starting here",
);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this logic be completely replaced with the snapshot parse attempt unconditionally? Or is it that we have advanced too much already and consumed part of the pattern by now specifically because of &?

Copy link
Member Author

@compiler-errors compiler-errors Jun 8, 2022

Choose a reason for hiding this comment

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

yeah, for example, in:

match &Foo {
  &Foo { a: 1 } => ()
  &Foo { a } => (),
}

we would have consumed the & token and Foo { .. } as the operator and RHS of operator & in the second arm before getting here, which means we have to handle it differently. Specifically, we can't recover so that the next arm parse is bound to be successful.

@estebank
Copy link
Contributor

estebank commented Jun 7, 2022

r=me if deduplication isn't feasible

@compiler-errors
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jun 8, 2022

📌 Commit b13eb61 has been approved by estebank

@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 Jun 8, 2022
@compiler-errors
Copy link
Member Author

@bors rollup

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 8, 2022
…-arm, r=estebank

Recover missing comma after match arm

If we're missing a comma after a match arm expression, try parsing another pattern and a following `=>`. If we find both of those, then recover by suggesting to insert a `,`.

Fixes rust-lang#80112
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 8, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97595 (Remove unwrap from get_vtable)
 - rust-lang#97597 (Preserve unused pointer to address casts)
 - rust-lang#97819 (Recover `import` instead of `use` in item)
 - rust-lang#97823 (Recover missing comma after match arm)
 - rust-lang#97851 (Use repr(C) when depending on struct layout in ptr tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a90c5a3 into rust-lang:master Jun 8, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 8, 2022
@compiler-errors compiler-errors deleted the missing-comma-match-arm branch August 11, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest adding a comma when match arm expression is followed by a pattern
6 participants