-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Improve parser diagnostics #95211
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -548,6 +548,22 @@ impl<'a> Parser<'a> { | |
is_present | ||
} | ||
|
||
fn check_noexpect(&self, tok: &TokenKind) -> bool { | ||
|
||
self.token == *tok | ||
} | ||
|
||
/// Consumes a token 'tok' if it exists. Returns whether the given token was present. | ||
/// | ||
/// the main purpose of this function is to reduce the cluttering of the suggestions list | ||
/// which using the normal eat method could introduce in some cases. | ||
pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool { | ||
let is_present = self.check_noexpect(tok); | ||
if is_present { | ||
self.bump() | ||
} | ||
is_present | ||
} | ||
|
||
/// Consumes a token 'tok' if it exists. Returns whether the given token was present. | ||
pub fn eat(&mut self, tok: &TokenKind) -> bool { | ||
let is_present = self.check(tok); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `enum` | ||
error: expected one of `;`, `}`, or an operator, found keyword `enum` | ||
--> $DIR/can-begin-expr-check.rs:19:12 | ||
| | ||
LL | return enum; | ||
| ^^^^ expected one of `.`, `;`, `?`, `}`, or an operator | ||
| ^^^^ expected one of `;`, `}`, or an operator | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub struct Entry<'a, K, V> { | ||
k: &'a mut K, | ||
v: V, | ||
} | ||
|
||
pub fn entry<'a, K, V>() -> Entry<'a K, V> { | ||
// ^ missing comma | ||
//~^^ expected one of `,` or `>`, found `K` | ||
unimplemented!() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected one of `,` or `>`, found `K` | ||
--> $DIR/issue-93867.rs:6:38 | ||
| | ||
LL | pub fn entry<'a, K, V>() -> Entry<'a K, V> { | ||
| ^ expected one of `,` or `>` | ||
| | ||
help: you might have meant to end the type parameters here | ||
| | ||
LL | pub fn entry<'a, K, V>() -> Entry<'a> K, V> { | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.