rust/compiler/rustc_parse/src/parser
Jonathan Brouwer 9ef76797ea
Rollup merge of #150590 - ident-kw-ice, r=petrochenkov
Don't try to recover keyword as non-keyword identifier

Fixes rust-lang/rust#149692.

On beta after rust-lang/rust#146978, we ICE on

```rs
macro_rules! m {
    ($id:item()) => {}
}

m!(Self());
```

where `Self` in the macro invocation is a keyword not a "normal" identifier, while attempting to recover an missing keyword before an identifier. Except, `Self` *is* a keyword, so trying to parse that as a non-reserved identifier expectedly fails.

I suspect rust-lang/rust#146978 merely unmasked a possible code path to hit this case; this logic has been so for a good while. Previously, on stable, the error message looks something like

```rs
error: expected identifier, found keyword `Self`
 --> src/lib.rs:5:4
  |
5 | m!(Self());
  |    ^^^^ expected identifier, found keyword

error: missing `fn` or `struct` for function or struct definition
 --> src/lib.rs:5:4
  |
2 |     ($id:item()) => {}
  |      -------- while parsing argument for this `item` macro fragment
...
5 | m!(Self());
  |    ^^^^
  |
help: if you meant to call a macro, try
  |
5 | m!(Self!());
  |        +
```

I considered restoring this diagnostic, but I'm not super convinced it's worth the complexity (and to me, it's not super clear what the user actually intended here).
2026-01-14 22:29:56 +01:00
..
tokenstream Use Iterator::eq and (dogfood) eq_by in compiler and library 2025-09-29 08:08:05 +03:00
asm.rs Don't use matches! when == suffices 2025-12-26 20:28:19 +00:00
attr.rs Create a rustc_ast representation for parsed attributes 2026-01-06 09:03:35 +01:00
attr_wrapper.rs Make attr path symbols rather than idents 2025-12-22 16:26:14 +01:00
cfg_select.rs Move parse_cfg_select to rustc_builtin_macros 2025-11-09 16:08:00 +01:00
diagnostics.rs Change some matches!(.., .. if ..) with let-chains 2026-01-13 17:13:22 +00:00
expr.rs Fix parsing of mgca const blocks in array repeat exprs 2025-12-30 11:30:31 -08:00
generics.rs Add contract variable declarations 2025-10-18 15:00:34 +01:00
item.rs Rollup merge of #150590 - ident-kw-ice, r=petrochenkov 2026-01-14 22:29:56 +01:00
mod.rs Change some matches!(.., .. if ..) with let-chains 2026-01-13 17:13:22 +00:00
nonterminal.rs Remove boxes from ast Pat lists 2025-10-04 12:39:58 -05:00
pat.rs Fix ICE by rejecting const blocks in patterns during AST lowering 2025-12-26 18:14:42 +07:00
path.rs Fix parsing of mgca const blocks in array repeat exprs 2025-12-30 11:30:31 -08:00
stmt.rs Use let...else consistently in user-facing diagnostics 2025-11-24 11:41:52 +09:00
tests.rs Remove out of date FIXME comment. 2026-01-08 14:54:26 +11:00
token_type.rs Experimentally add *heterogeneous* try blocks 2025-12-09 20:18:43 -08:00
ty.rs Fix parsing of mgca const blocks in array repeat exprs 2025-12-30 11:30:31 -08:00