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

Use heuristics to recover parsing of missing ; #65640

Merged
merged 3 commits into from
Oct 29, 2019

Conversation

estebank
Copy link
Contributor

  • Detect , and : typos where ; was intended.
  • When the next token could have been the start of a new statement,
    detect a missing semicolon.

Fix #48160, fix #44767 (after adding note about statements).

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(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 Oct 20, 2019
@estebank
Copy link
Contributor Author

Still needs a bit of a clean up, but the idea is to detect some common typos that can occur during development and the lack of a semicolon, which is also quite common when writing code.

@rust-highfive

This comment has been minimized.

@Centril Centril self-assigned this Oct 20, 2019
src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/token.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser/diagnostics.rs Show resolved Hide resolved
src/libsyntax/parse/parser/item.rs Show resolved Hide resolved
@rust-highfive

This comment has been minimized.

@estebank estebank changed the title [wip] Use heuristics to recover parsing of missing ; Use heuristics to recover parsing of missing ; Oct 22, 2019
@rust-highfive

This comment has been minimized.

@RalfJung
Copy link
Member

Could not resolve host: rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com

@bors retry

@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 Oct 22, 2019
@petrochenkov petrochenkov removed their assignment Oct 22, 2019
@estebank
Copy link
Contributor Author

r? @Centril

src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
// When the spans are in the same line, it means that the only content
// between them is whitespace, point only at the found token.
err.span_label(sp, label_exp);
if !sm.is_multiline(prev_sp.until(sp)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic here seems very similar to the case in my comment above -- a refactoring opportunity?

src/libsyntax/parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
@Centril Centril 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 Oct 24, 2019
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2019
LL | let _ = 3;
| ^^^
| --- unexpected token
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the look of this error, but it is slightly misleading because it could have been any of the other expected tokens, but given it was followed by a "token capable of starting statement", I feel comfortable to ignore the other possibilities. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable as a heuristic. You could optionally add a note below for the additional expected tokens. I'll leave that up to you.

--> $DIR/issue-54441.rs:3:9
|
LL | let
| ^^^ unexpected token
| ^^^ expected one of `crate`, `fn`, `pub`, `static`, or `type` here

Choose a reason for hiding this comment

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

In the change above this one the word here is removed in this PR (“ ^^ expected fn here”), while it is still present in this change.

Is that as intended?

Copy link
Contributor Author

@estebank estebank Oct 28, 2019

Choose a reason for hiding this comment

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

Updated these as well, but they affect a huge amount of tests, I'll leave it as a separate PR.

@Centril
Copy link
Contributor

Centril commented Oct 26, 2019

r=me with or without the additional note and "here".

@Centril Centril 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2019
- Detect `,` and `:` typos where `;` was intended.
- When the next token could have been the start of a new statement,
  detect a missing semicolon.
@estebank estebank force-pushed the recover-missing-semi branch 2 times, most recently from 3a7e597 to e8016c2 Compare October 28, 2019 18:10
@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented Oct 28, 2019

📌 Commit e8016c2 has been approved by Centril

@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 Oct 28, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 28, 2019
…ntril

Use heuristics to recover parsing of missing `;`

- Detect `,` and `:` typos where `;` was intended.
- When the next token could have been the start of a new statement,
  detect a missing semicolon.

Fix rust-lang#48160, fix rust-lang#44767 (after adding note about statements).
bors added a commit that referenced this pull request Oct 28, 2019
Rollup of 9 pull requests

Successful merges:

 - #65563 (Add long error explanation for E0587)
 - #65640 (Use heuristics to recover parsing of missing `;`)
 - #65643 (Correct handling of type flags with `ConstValue::Placeholder`)
 - #65825 (rustc: use IndexVec<DefIndex, T> instead of Vec<T>.)
 - #65858 (suggest `const_in_array_repeat_expression` flag)
 - #65877 (doc: introduce `once` in `iter::chain` document)
 - #65887 (doc: mention `get(_mut)` in Vec)
 - #65891 (self-profiling: Record something more useful for crate metadata generation event.)
 - #65893 (Output previous stable  error messaging when using stable build.)

Failed merges:

r? @ghost
@bors bors merged commit e8016c2 into rust-lang:master Oct 29, 2019
@bors
Copy link
Contributor

bors commented Oct 29, 2019

☔ The latest upstream changes (presumably #65907) made this pull request unmergeable. Please resolve the merge conflicts.

@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 Oct 29, 2019
@estebank estebank deleted the recover-missing-semi branch November 9, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parser should recover from seeing , when ; is expected Confusing parse error with let bindings
7 participants