1
Fork 0

refactor: improve "ident starts with number" error

This commit is contained in:
Ezra Shaw 2023-03-17 21:41:26 +13:00
parent c9ddb73184
commit b4e17a5098
No known key found for this signature in database
GPG key ID: 67ABF16FB0ECD870
6 changed files with 61 additions and 20 deletions

View file

@ -348,10 +348,6 @@ impl<'a> Parser<'a> {
lo = self.token.span;
}
if self.is_lit_bad_ident() {
return Err(self.expected_ident_found());
}
let pat = if self.check(&token::BinOp(token::And)) || self.token.kind == token::AndAnd {
self.parse_pat_deref(expected)?
} else if self.check(&token::OpenDelim(Delimiter::Parenthesis)) {
@ -395,7 +391,7 @@ impl<'a> Parser<'a> {
} else {
PatKind::Lit(const_expr)
}
} else if self.can_be_ident_pat() {
} else if self.can_be_ident_pat() || self.is_lit_bad_ident().is_some() {
// Parse `ident @ pat`
// This can give false positives and parse nullary enums,
// they are dealt with later in resolve.