Merge pull request #579 from Kijewski/6380739026550784

parser: `r#_` is not a valid identifier
This commit is contained in:
Guillaume Gomez 2025-08-19 23:09:10 +02:00 committed by GitHub
commit a9f56e3aa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 5 deletions

View File

@ -9,9 +9,8 @@ use winnow::token::{any, one_of, take, take_until};
use crate::node::CondTest;
use crate::{
CharLit, ErrorContext, HashSet, InputStream, Num, ParseResult, PathOrIdentifier, StrLit,
StrPrefix, WithSpan, can_be_variable_name, char_lit, cut_error, filter, identifier,
is_rust_keyword, keyword, not_suffix_with_hash, num_lit, path_or_identifier, skip_ws0,
skip_ws1, str_lit, ws,
StrPrefix, WithSpan, char_lit, cut_error, filter, identifier, is_rust_keyword, keyword,
not_suffix_with_hash, num_lit, path_or_identifier, skip_ws0, skip_ws1, str_lit, ws,
};
macro_rules! expr_prec_layer {
@ -1100,7 +1099,7 @@ impl<'a: 'l, 'l> Suffix<'a> {
)
} else {
// a raw identifier like `r#async`
if !can_be_variable_name(id) {
if matches!(id, "self" | "Self" | "super" | "crate" | "_") {
cut_error!(
format!("`{}` cannot be a raw identifier", id.escape_debug()),
span,

View File

@ -1625,7 +1625,7 @@ fn test_macro_call_illegal_raw_identifier() {
// Regression test for <https://issues.oss-fuzz.com/issues/435218013>.
let syntax = Syntax::default();
for id in ["crate", "self", "Self", "super"] {
for id in ["crate", "self", "Self", "super", "_"] {
assert!(
Ast::from_str(&format!("{{{{ z!(r#{id}) }}}}"), None, &syntax)
.unwrap_err()