diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index f31e634f55c8b..2c98feeece775 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -387,8 +387,8 @@ impl<'a> Parser<'a> { let span = if is_pub { self.prev_token.span.to(ident_span) } else { ident_span }; let insert_span = ident_span.shrink_to_lo(); - let ident = if (!is_const - || self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Parenthesis))) + let ident = if self.token.is_ident() + && (!is_const || self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Parenthesis))) && self.look_ahead(1, |t| { [ token::Lt, diff --git a/tests/ui/parser/ice-issue-127600.rs b/tests/ui/parser/ice-issue-127600.rs new file mode 100644 index 0000000000000..709c10253266d --- /dev/null +++ b/tests/ui/parser/ice-issue-127600.rs @@ -0,0 +1,2 @@ +const!(&raw mut a); +//~^ ERROR expected identifier, found `!` diff --git a/tests/ui/parser/ice-issue-127600.stderr b/tests/ui/parser/ice-issue-127600.stderr new file mode 100644 index 0000000000000..629fc4ae40b67 --- /dev/null +++ b/tests/ui/parser/ice-issue-127600.stderr @@ -0,0 +1,8 @@ +error: expected identifier, found `!` + --> $DIR/ice-issue-127600.rs:1:6 + | +LL | const!(&raw mut a); + | ^ expected identifier + +error: aborting due to 1 previous error +