rust/compiler/rustc_parse/src
Matthias Krüger 1fd0c71818
Rollup merge of #120221 - compiler-errors:statements-are-not-patterns, r=nnethercote
Don't make statement nonterminals match pattern nonterminals

Right now, the heuristic we use to check if a token may begin a pattern nonterminal falls back to `may_be_ident`:
ef71f1047e/compiler/rustc_parse/src/parser/nonterminal.rs (L21-L37)

This has the unfortunate side effect that a `stmt` nonterminal eagerly matches against a `pat` nonterminal, leading to a parse error:
```rust
macro_rules! m {
    ($pat:pat) => {};
    ($stmt:stmt) => {};
}

macro_rules! m2 {
    ($stmt:stmt) => {
        m! { $stmt }
    };
}

m2! { let x = 1 }
```

This PR fixes it by more accurately reflecting the set of nonterminals that may begin a pattern nonterminal.

As a side-effect, I modified `Token::can_begin_pattern` to work correctly and used that in `Parser::nonterminal_may_begin_with`.
2024-08-31 10:08:51 +02:00
..
lexer Use impl PartialEq<TokenKind> for Token more. 2024-08-14 16:37:09 +10:00
parser Rollup merge of #120221 - compiler-errors:statements-are-not-patterns, r=nnethercote 2024-08-31 10:08:51 +02:00
errors.rs Add warn(unreachable_pub) to rustc_parser. 2024-08-29 20:13:06 +10:00
lib.rs Add warn(unreachable_pub) to rustc_parser. 2024-08-29 20:13:06 +10:00
validate_attr.rs Stabilize unsafe_attributes 2024-08-07 03:12:13 -05:00