diff options
| author | trevyn <230691+trevyn@users.noreply.github.com> | 2024-07-11 12:12:00 +0400 |
|---|---|---|
| committer | trevyn <230691+trevyn@users.noreply.github.com> | 2024-07-11 12:12:00 +0400 |
| commit | a01f49e7f32b39b77f6a5804c1ed12aadaa89ec5 (patch) | |
| tree | 7d3ecfbca94228f9e6f19e14692cdf75a1e2ada5 | |
| parent | 8c39ac9eccdfaeff11bd3b6107817a81fe0a3a43 (diff) | |
| download | rust-a01f49e7f32b39b77f6a5804c1ed12aadaa89ec5.tar.gz rust-a01f49e7f32b39b77f6a5804c1ed12aadaa89ec5.zip | |
check is_ident before parse_ident
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 4 | ||||
| -rw-r--r-- | tests/ui/parser/ice-issue-127600.rs | 2 | ||||
| -rw-r--r-- | tests/ui/parser/ice-issue-127600.stderr | 8 |
3 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index f31e634f55c..2c98feeece7 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 00000000000..709c1025326 --- /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 00000000000..629fc4ae40b --- /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 + |
