Add regression tests for keyword-in-identifier-position recovery ICE

... in macro invocations.

Issue: <https://github.com/rust-lang/rust/issues/149692>.
This commit is contained in:
Jieyou Xu 2026-01-02 17:26:41 +08:00
parent a47f4dfd7f
commit 31531b3665
No known key found for this signature in database
GPG key ID: 045B995028EA6AFC
4 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,11 @@
//! More test coverage for <https://github.com/rust-lang/rust/issues/149692>; this test is
//! specifically for `const` items.
macro_rules! m {
(const $id:item()) => {}
}
m!(const Self());
//~^ ERROR expected one of `!` or `::`, found `(`
fn main() {}

View file

@ -0,0 +1,11 @@
error: expected one of `!` or `::`, found `(`
--> $DIR/kw-in-const-item-pos-recovery-149692.rs:8:14
|
LL | (const $id:item()) => {}
| -------- while parsing argument for this `item` macro fragment
...
LL | m!(const Self());
| ^ expected one of `!` or `::`
error: aborting due to 1 previous error

View file

@ -0,0 +1,19 @@
//! Regression test for a diagnostic ICE where we tried to recover a keyword as the identifier when
//! we are already trying to recover a missing keyword before item.
//!
//! See <https://github.com/rust-lang/rust/issues/149692>.
macro_rules! m {
($id:item()) => {}
}
m!(Self());
//~^ ERROR expected one of `!` or `::`, found `(`
m!(Self{});
//~^ ERROR expected one of `!` or `::`, found `{`
m!(crate());
//~^ ERROR expected one of `!` or `::`, found `(`
fn main() {}

View file

@ -0,0 +1,29 @@
error: expected one of `!` or `::`, found `(`
--> $DIR/kw-in-item-pos-recovery-149692.rs:10:8
|
LL | ($id:item()) => {}
| -------- while parsing argument for this `item` macro fragment
...
LL | m!(Self());
| ^ expected one of `!` or `::`
error: expected one of `!` or `::`, found `{`
--> $DIR/kw-in-item-pos-recovery-149692.rs:13:8
|
LL | ($id:item()) => {}
| -------- while parsing argument for this `item` macro fragment
...
LL | m!(Self{});
| ^ expected one of `!` or `::`
error: expected one of `!` or `::`, found `(`
--> $DIR/kw-in-item-pos-recovery-149692.rs:16:9
|
LL | ($id:item()) => {}
| -------- while parsing argument for this `item` macro fragment
...
LL | m!(crate());
| ^ expected one of `!` or `::`
error: aborting due to 3 previous errors