about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorVincenzo Palazzo <vincenzopalazzodev@gmail.com>2024-05-31 16:47:30 +0000
committerVincenzo Palazzo <vincenzopalazzodev@gmail.com>2024-07-31 18:34:22 +0000
commit276fa19c0a85a341c5b9fddb4ffb17282907532e (patch)
tree863a6f02bb33f76700d8b604ca13063eb22da990 /compiler/rustc_parse/src
parent47243b335e02c341528dd3beb77fa0e030d7ccda (diff)
downloadrust-276fa19c0a85a341c5b9fddb4ffb17282907532e.tar.gz
rust-276fa19c0a85a341c5b9fddb4ffb17282907532e.zip
rustc_parser: 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
Co-authored-by: Eric Holk <eric@theincredibleholk.org>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/nonterminal.rs11
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 886d6af1735..730b3a57142 100644
--- a/compiler/rustc_parse/src/parser/nonterminal.rs
+++ b/compiler/rustc_parse/src/parser/nonterminal.rs
@@ -38,6 +38,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.
@@ -45,8 +46,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, `_` will be 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)
             }