-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
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. |
This comment has been minimized.
This comment has been minimized.
1b45a9b
to
dd05f9f
Compare
This comment has been minimized.
This comment has been minimized.
;
;
This comment has been minimized.
This comment has been minimized.
@bors retry |
44947a8
to
7232f47
Compare
r? @Centril |
// 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)) { |
There was a problem hiding this comment.
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?
This comment has been minimized.
This comment has been minimized.
de4d5fb
to
01741d2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
01741d2
to
1c1778b
Compare
LL | let _ = 3; | ||
| ^^^ | ||
| --- unexpected token |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
r=me with or without the additional note and "here". |
- Detect `,` and `:` typos where `;` was intended. - When the next token could have been the start of a new statement, detect a missing semicolon.
3a7e597
to
e8016c2
Compare
@bors r=Centril |
📌 Commit e8016c2 has been approved by |
…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).
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
☔ The latest upstream changes (presumably #65907) made this pull request unmergeable. Please resolve the merge conflicts. |
,
and:
typos where;
was intended.detect a missing semicolon.
Fix #48160, fix #44767 (after adding note about statements).