-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 parser diagnostics #95211
Improve parser diagnostics #95211
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
aa01a0b
to
3f8fdb7
Compare
could you take a look at this cuz i took some inspiration from your comments and you seemed to be interested in smth like this as well? |
I cannot r+ this (and hence high-five bot didn't assign me), but I will certainly take a look! |
lol, nvm, highfive-bot does not care about bors permissions apparently. anywho, I cannot approve this for you, so I will reassign this to someone who can. I will try to give it a review though! r? rust-lang/compiler |
@bors delegate=compiler-errors @compiler-errors if you want to review this, go for it (I'll try to look at this regardless later today) |
✌️ @compiler-errors can now approve this pull request |
7bd0c28
to
2ae9da9
Compare
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 am concerned with a regression in parsing fn foo() where {}
. Also left a few other comments.
@@ -19,6 +24,11 @@ LL | false | |||
LL | /*! bar */ | |||
| ^^^^^^^^^^ unexpected token | |||
| | |||
help: Consider removing this 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.
It is somewhat misleading to call this a "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.
What name would you suggest, i am willing to adjust this
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.
Can you special-case this for certain tokens?
Also, not sure if the suggestion to remove a comment is useful here, since comments are usually intentionally placed. This one might be better fixed with a separate suggestion.
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.
Can you special-case this for certain tokens?
Also, not sure if the suggestion to remove a comment is useful here, since comments are usually intentionally placed. This one might be better fixed with a separate suggestion.
Oh, yea i can special case different token kinds and i can ignore comments i 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.
Okay, so i made it vary based on the kind of token
I fixed this regression by downgrading the diagnostic from an error to a warning |
e57b61b
to
0839c08
Compare
This comment has been minimized.
This comment has been minimized.
@terrarier2111, is it too much work to split this up into several commits? We might want to land some of these diagnostics separately, possibly so it's easier to git-bisect later on, and because they are varying levels of opinionated. Or at least, several commits might be easier to review. For example, I could see the |
if !ignore | ||
&& self.look_ahead(1, |next| { | ||
is_ident_eq_keyword(next.kind.clone(), token.clone()) | ||
}) | ||
{ | ||
suggest_removing = true; | ||
} | ||
if let TokenType::Token(kind) = token.clone() { | ||
if !ignore && self.look_ahead(1, |next| kind == next.kind) { | ||
suggest_removing = true; | ||
} | ||
if kind == self.token.kind { | ||
None | ||
} else { | ||
Some(token) | ||
} | ||
} else { | ||
Some(token) | ||
} | ||
} | ||
} else { | ||
None | ||
} | ||
}) |
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.
Do you mind leaving comments explaining what this logic is checking for? Also, perhaps using return
might help tighten some of the if-else blocks.
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 left some comments there and used returns, do the comments suffice?
Do you mean splitting these commits in different prs or just having multiple commits in this pr? |
5f29e26
to
a1df86e
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #94495) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Sorry for taking some time to get back to this. I have a couple of comments.
d5e2166
to
637ce71
Compare
@@ -548,6 +548,22 @@ impl<'a> Parser<'a> { | |||
is_present | |||
} | |||
|
|||
fn check_noexpect(&self, tok: &TokenKind) -> bool { |
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.
can you double check if the parser has other self.token ==
use cases that can be turned into check_noexpect
?
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 that i am able to do that as from what I was able to see that would require a decent amount of work and I just wanted to finish up the changes in this pr.
@terrarier2111, heads up that PRs should not include merge commits: https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy |
@compiler-errors Yea, i know i wanted to finish this later |
7a47722
to
70589ba
Compare
Heads up that you messed up the commit log I think: https://github.com/rust-lang/rust/pull/95211/commits |
Oh.. yea how could I solve this problem? |
perhaps |
70589ba
to
2fd7808
Compare
Okay, well so i tried fixing it and actually made it worse :c |
I'm not sure if I can help -- I'm not familiar with the |
2fd7808
to
c88e4fb
Compare
ecbeac0
to
21fdd54
Compare
@compiler-errors do I have to do anything else for this to be good to go? |
This looks fine enough to merge now. Maybe we actually don't need the noexpect methods, but those are easy to remove. @bors r+ |
📌 Commit 21fdd54 has been approved by |
Rollup of 4 pull requests Successful merges: - rust-lang#95211 (Improve parser diagnostics) - rust-lang#95243 (Add Apple WatchOS compile targets) - rust-lang#97385 (Add WIP stable MIR crate) - rust-lang#97508 (Harden bad placeholder checks on statics/consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This pr fixes #93867 and contains a couple of diagnostics related changes to the parser.
Here is a short list with some of the changes:
If any of these changes are undesirable, i can remove them, thanks!