From 276fa19c0a85a341c5b9fddb4ffb17282907532e Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Fri, 31 May 2024 16:47:30 +0000 Subject: 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 Signed-off-by: Vincenzo Palazzo --- compiler/rustc_parse/src/parser/nonterminal.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src/parser') 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) } -- cgit 1.4.1-3-g733a5 From 79ef91e879d15bf13b8903379c36c08ad4788587 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 31 Jul 2024 15:37:55 -0400 Subject: tweak comment on `NonterminalKind::Expr` Co-authored-by: Eric Holk --- compiler/rustc_parse/src/parser/nonterminal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 730b3a57142..54f4a4ead07 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -48,7 +48,7 @@ impl<'a> Parser<'a> { } // Current edition expressions NonterminalKind::Expr(Expr) => { - // In Edition 2024, `_` will be considered an expression, so we + // 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. // -- cgit 1.4.1-3-g733a5