Add Ident::is_non_reserved_ident

This commit is contained in:
Michael Goulet
2025-06-26 17:53:01 +00:00
parent 3b9d04c62f
commit 94e9973b92
7 changed files with 14 additions and 15 deletions

View File

@@ -2731,7 +2731,7 @@ impl<'a> Parser<'a> {
return first_pat;
}
if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..))
|| !self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
|| !self.look_ahead(1, |token| token.is_non_reserved_ident())
{
let mut snapshot_type = self.create_snapshot_for_diagnostic();
snapshot_type.bump(); // `:`

View File

@@ -3875,8 +3875,7 @@ impl<'a> Parser<'a> {
// Check if a colon exists one ahead. This means we're parsing a fieldname.
let is_shorthand = !this.look_ahead(1, |t| t == &token::Colon || t == &token::Eq);
// Proactively check whether parsing the field will be incorrect.
let is_wrong = this.token.is_ident()
&& !this.token.is_reserved_ident()
let is_wrong = this.token.is_non_reserved_ident()
&& !this.look_ahead(1, |t| {
t == &token::Colon
|| t == &token::Eq

View File

@@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
/// Is the given keyword `kw` followed by a non-reserved identifier?
fn is_kw_followed_by_ident(&self, kw: Symbol) -> bool {
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_non_reserved_ident())
}
#[inline]

View File

@@ -126,7 +126,7 @@ impl<'a> Parser<'a> {
/// ```
fn recover_colon_before_qpath_proj(&mut self) -> bool {
if !self.check_noexpect(&TokenKind::Colon)
|| self.look_ahead(1, |t| !t.is_ident() || t.is_reserved_ident())
|| self.look_ahead(1, |t| !t.is_non_reserved_ident())
{
return false;
}
@@ -260,7 +260,7 @@ impl<'a> Parser<'a> {
if self.may_recover()
&& style == PathStyle::Expr // (!)
&& self.token == token::Colon
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
&& self.look_ahead(1, |token| token.is_non_reserved_ident())
{
// Emit a special error message for `a::b:c` to help users
// otherwise, `a: c` might have meant to introduce a new binding
@@ -334,9 +334,7 @@ impl<'a> Parser<'a> {
self.expect_gt().map_err(|mut err| {
// Try to recover a `:` into a `::`
if self.token == token::Colon
&& self.look_ahead(1, |token| {
token.is_ident() && !token.is_reserved_ident()
})
&& self.look_ahead(1, |token| token.is_non_reserved_ident())
{
err.cancel();
err = self.dcx().create_err(PathSingleColon {

View File

@@ -798,7 +798,7 @@ impl<'a> Parser<'a> {
}
if self.prev_token.is_reserved_ident() && self.prev_token.is_ident_named(kw::Await) {
// Likely `foo.await bar`
} else if !self.prev_token.is_reserved_ident() && self.prev_token.is_ident() {
} else if self.prev_token.is_non_reserved_ident() {
// Likely `foo bar`
} else if self.prev_token.kind == token::Question {
// `foo? bar`