-
Notifications
You must be signed in to change notification settings - Fork 13k
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
libsyntax/parse: fix missing kind error reporting #41282
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @petrochenkov - how do I add error recovery? |
src/libsyntax/parse/parser.rs
Outdated
.struct_span_err(sp, "missing `fn` for method declaration"); | ||
err.span_label(sp, &"missing `fn`"); | ||
} | ||
if !self.eat(&token::Not) { |
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'd also add path.segments.len() == 1
to the condition for mistyped impl item declaration.
As for recovery, if the current token is (
then err
can be emitted immediately as non-fatal (err.emit()
) and we can parse remaining tokens as a method.
If the current token is :
then remaining tokens can be parsed as an associated type (statistically more likely), but there's a chance for confusing error if it's actually an associated const, and this probably doesn't matter as much as methods.
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.
What to do if path.segments.len() != 1
?
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.
What to do if
path.segments.len() != 1
?
Report missing !
and continue parsing as a macro, most likely.
@@ -0,0 +1,10 @@ | |||
error: missing `fn`, `type`, or `const` for impl-item declaration |
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 file shouldn't be in the PR.
ddcadbe
to
d648c10
Compare
Now with error recovery. |
@bors r+ |
📌 Commit d648c10 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Fixes #41161.
Fixes #41239.