diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-31 23:20:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-31 23:20:09 +0200 |
| commit | 3acd910036eee61272e9adbe8ab73867bf19103e (patch) | |
| tree | 2e9224933252795da5abe441742349262d2599b5 /compiler/rustc_parse/src/parser | |
| parent | 20379e4d4ecb87605e0fcc3cb4b2eea7c3ee2346 (diff) | |
| parent | 79ef91e879d15bf13b8903379c36c08ad4788587 (diff) | |
| download | rust-3acd910036eee61272e9adbe8ab73867bf19103e.tar.gz rust-3acd910036eee61272e9adbe8ab73867bf19103e.zip | |
Rollup merge of #126697 - vincenzopalazzo:macros/find_the_expression_tok, r=eholk,compiler-errors
[RFC] mbe: consider the `_` in 2024 an expression This commit is adding the possibility to parse the `_` as an expression inside the esition 2024. Link: https://rust-lang.zulipchat.com/#narrow/stream/404510-wg-macros/topic/supporting.20.60_.60.20expressions Issue https://github.com/rust-lang/rust/issues/123742 r? `@eholk`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index bd9d96ba573..999f6f0eeb0 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -39,6 +39,7 @@ impl<'a> Parser<'a> { } match kind { + // `expr_2021` and earlier NonterminalKind::Expr(Expr2021 { .. }) => { token.can_begin_expr() // This exception is here for backwards compatibility. @@ -46,8 +47,16 @@ impl<'a> Parser<'a> { // This exception is here for backwards compatibility. && !token.is_keyword(kw::Const) } + // Current edition expressions NonterminalKind::Expr(Expr) => { - token.can_begin_expr() + // In Edition 2024, `_` is considered an expression, so we + // need to allow it here because `token.can_begin_expr()` does + // not consider `_` to be an expression. + // + // Because `can_begin_expr` is used elsewhere, we need to reduce + // the scope of where the `_` is considered an expression to + // just macro parsing code. + (token.can_begin_expr() || token.is_keyword(kw::Underscore)) // This exception is here for backwards compatibility. && !token.is_keyword(kw::Let) } |
