about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-06-21 09:12:36 +0200
committerGitHub <noreply@github.com>2024-06-21 09:12:36 +0200
commit3bd84f18bca50a4617a4b367f45ec39a57ce8615 (patch)
tree27c173b7f8963d89255a09edd3d968b10e53ff86 /compiler/rustc_expand/src/mbe
parent2b7f6e274e2a18cb2dd7beaa06575f907640ecfc (diff)
parent3e8898a4e1afd44f09a5a80d466cd5b1a87e0fa8 (diff)
downloadrust-3bd84f18bca50a4617a4b367f45ec39a57ce8615.tar.gz
rust-3bd84f18bca50a4617a4b367f45ec39a57ce8615.zip
Rollup merge of #126700 - compiler-errors:fragment, r=fmease
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo```
cc #123865

Tracking:

- https://github.com/rust-lang/rust/issues/123742
Diffstat (limited to 'compiler/rustc_expand/src/mbe')
-rw-r--r--compiler/rustc_expand/src/mbe/macro_rules.rs4
-rw-r--r--compiler/rustc_expand/src/mbe/quoted.rs3
2 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs
index 49b1f5ce0e3..0050ff10539 100644
--- a/compiler/rustc_expand/src/mbe/macro_rules.rs
+++ b/compiler/rustc_expand/src/mbe/macro_rules.rs
@@ -1292,7 +1292,9 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
                 // maintain
                 IsInFollow::Yes
             }
-            NonterminalKind::Stmt | NonterminalKind::Expr | NonterminalKind::Expr2021 => {
+            NonterminalKind::Stmt
+            | NonterminalKind::Expr
+            | NonterminalKind::Expr2021 { inferred: _ } => {
                 const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
                 match tok {
                     TokenTree::Token(token) => match token.kind {
diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs
index 74f78c0ef78..fdf187438d3 100644
--- a/compiler/rustc_expand/src/mbe/quoted.rs
+++ b/compiler/rustc_expand/src/mbe/quoted.rs
@@ -113,7 +113,8 @@ pub(super) fn parse(
                                                 );
                                                 token::NonterminalKind::Ident
                                             });
-                                    if kind == token::NonterminalKind::Expr2021
+                                    if kind
+                                        == (token::NonterminalKind::Expr2021 { inferred: false })
                                         && !features.expr_fragment_specifier_2024
                                     {
                                         rustc_session::parse::feature_err(