-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve parse item fallback #125388
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
base: master
Are you sure you want to change the base?
Improve parse item fallback #125388
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
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 don't think this PR solves #101622 :(
.dcx() | ||
.struct_span_err(self.token.span, format!("expected item, found {token_str}")); | ||
|
||
match self.parse_full_stmt(AttemptLocalParseRecovery::No) { |
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.
We'd be better doing more analysis to figure out what went wrong here, rather than treating them all as statements. For example, whether it contains ;
in []
can be used to distinguish whether it is an attribute or an array.
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 gave up on trying to detect kinds of expressions as it's very unreliable.
It addresses the main point raised in the issue, right? |
9a129e5
to
06a1ccf
Compare
@rustbot ready |
☔ The latest upstream changes (presumably #126049) made this pull request unmergeable. Please resolve the merge conflicts. |
06a1ccf
to
1d326d5
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot author |
3f2ccd7
to
b9ddf53
Compare
b9ddf53
to
c66b446
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #127906) made this pull request unmergeable. Please resolve the merge conflicts. |
@dev-ardi |
It was left unreviewed for a while so it became full of conflicts. I intend to finish it at some point though... |
57d1590
to
faf1c5f
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
faf1c5f
to
b40be9d
Compare
r? @SparrowLii (but feel free to roll the review assignment to someone else) |
r? diagnostics |
r? diagnostics |
"Should have been handled by maybe_consume_incorrect_semicolon" | ||
); | ||
} | ||
StmtKind::Item(_) | StmtKind::MacCall(_) => { |
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.
Item should be unreachable, right?
} | ||
StmtKind::Semi(expr) => { | ||
err.span_label(span, "unexpected expression").help(format!( | ||
"consider putting it inside a function: fn foo() {{ {}; }}", |
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.
This diagnostic can potentially become very big. Either use structured suggestions, or do not put a suggestion into the diagnostic message itself.
@@ -2,8 +2,11 @@ error: expected item, found `[` | |||
--> $DIR/shebang-doc-comment.rs:2:1 | |||
| | |||
LL | [allow(unused_variables)] |
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.
Maybe add a code path for array expressions and suggest adding a #
instead?
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
Closes #92615 and closes #101622
Please review the new diagnostics cafefully.
This PR also adds a few more comments to the parser.