Skip to content

Commit

Permalink
check is_ident before parse_ident
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Jul 11, 2024
1 parent 8c39ac9 commit a01f49e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/parser/ice-issue-127600.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const!(&raw mut a);
//~^ ERROR expected identifier, found `!`
8 changes: 8 additions & 0 deletions tests/ui/parser/ice-issue-127600.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a01f49e

Please sign in to comment.