-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Improve parse item fallback #125388
base: master
Are you sure you want to change the base?
Improve parse item fallback #125388
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
| | ||
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> | ||
= help: consider putting it inside a function: fn main() { [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.
Hm, I don't think we want to have this recovery, at least when you could parse it like a macro attr w/o a #
.
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.
Hm it thinks that it's an expression so it suggests putting it inside a function.
How can we tell that this is a bad attr and not an array literal with a function call?
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.
)); | ||
} | ||
StmtKind::MacCall(_) => { | ||
err.span_label(span, "unexpected macro call at this position"); |
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.
At least one example should be added for it
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.
you mean consider putting it inside a function
?
|
||
StmtKind::Semi(e) | StmtKind::Expr(e) => { | ||
err.span_label(span, "unexpected expression").help(format!( | ||
"consider putting it inside a function: fn main() {{ {} }}", |
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 tip also applies to the let
statement above
It addresses the main point raised in the issue, right? |
9a129e5
to
06a1ccf
Compare
@@ -76,6 +76,14 @@ pub fn attribute_to_string(attr: &ast::Attribute) -> String { | |||
State::new().attribute_to_string(attr) | |||
} | |||
|
|||
pub fn local_to_string(local: &ast::Local) -> String { |
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 ended up being useless but I don't think that it's bad to have, right?
@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
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ 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... |
Closes #92615 and closes #101622
Please review the new diagnostics cafefully.
This PR also adds a few more comments to the parser.