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

@@ -893,7 +893,7 @@ impl Token {
|| self.is_qpath_start()
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
|| self.is_path_segment_keyword()
|| self.is_ident() && !self.is_reserved_ident()
|| self.is_non_reserved_ident()
}
/// Returns `true` if the token is a given keyword, `kw`.
@@ -937,6 +937,10 @@ impl Token {
self.is_non_raw_ident_where(Ident::is_reserved)
}
pub fn is_non_reserved_ident(&self) -> bool {
self.ident().is_some_and(|(id, raw)| raw == IdentIsRaw::Yes || !Ident::is_reserved(id))
}
/// Returns `true` if the token is the identifier `true` or `false`.
pub fn is_bool_lit(&self) -> bool {
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())

View File

@@ -634,10 +634,8 @@ impl TokenStream {
(
TokenTree::Token(token_left, Spacing::Alone),
TokenTree::Token(token_right, _),
) if ((token_left.is_ident() && !token_left.is_reserved_ident())
|| token_left.is_lit())
&& ((token_right.is_ident() && !token_right.is_reserved_ident())
|| token_right.is_lit()) =>
) if (token_left.is_non_reserved_ident() || token_left.is_lit())
&& (token_right.is_non_reserved_ident() || token_right.is_lit()) =>
{
token_left.span
}