Skip to content

Commit 428af23

Browse files
committed
Auto merge of rust-lang#125389 - fmease:perf-expr_2021, r=<try>
[perf-only] Revert "Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal" CC rust-lang#123865 r? ghost
2 parents 39e02f1 + e8d39b6 commit 428af23

13 files changed

+24
-204
lines changed

compiler/rustc_ast/src/token.rs

-4
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,6 @@ pub enum NonterminalKind {
881881
},
882882
PatWithOr,
883883
Expr,
884-
/// Matches an expression using the rules from edition 2021 and earlier.
885-
Expr2021,
886884
Ty,
887885
Ident,
888886
Lifetime,
@@ -912,7 +910,6 @@ impl NonterminalKind {
912910
},
913911
sym::pat_param => NonterminalKind::PatParam { inferred: false },
914912
sym::expr => NonterminalKind::Expr,
915-
sym::expr_2021 if edition().at_least_rust_2021() => NonterminalKind::Expr2021,
916913
sym::ty => NonterminalKind::Ty,
917914
sym::ident => NonterminalKind::Ident,
918915
sym::lifetime => NonterminalKind::Lifetime,
@@ -932,7 +929,6 @@ impl NonterminalKind {
932929
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
933930
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
934931
NonterminalKind::Expr => sym::expr,
935-
NonterminalKind::Expr2021 => sym::expr_2021,
936932
NonterminalKind::Ty => sym::ty,
937933
NonterminalKind::Ident => sym::ident,
938934
NonterminalKind::Lifetime => sym::lifetime,

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
12931293
// maintain
12941294
IsInFollow::Yes
12951295
}
1296-
NonterminalKind::Stmt | NonterminalKind::Expr | NonterminalKind::Expr2021 => {
1296+
NonterminalKind::Stmt | NonterminalKind::Expr => {
12971297
const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
12981298
match tok {
12991299
TokenTree::Token(token) => match token.kind {

compiler/rustc_expand/src/mbe/quoted.rs

+21-50
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use rustc_span::Span;
1616
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
1717
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
1818
`literal`, `path`, `meta`, `tt`, `item` and `vis`";
19-
const VALID_FRAGMENT_NAMES_MSG_2021: &str = "valid fragment specifiers are \
20-
`ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, \
21-
`ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, \
22-
`item` and `vis`";
2319

2420
/// Takes a `tokenstream::TokenStream` and returns a `Vec<self::TokenTree>`. Specifically, this
2521
/// takes a generic `TokenStream`, such as is used in the rest of the compiler, and returns a
@@ -67,60 +63,35 @@ pub(super) fn parse(
6763
Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() {
6864
Some((fragment, _)) => {
6965
let span = token.span.with_lo(start_sp.lo());
70-
let edition = || {
71-
// FIXME(#85708) - once we properly decode a foreign
72-
// crate's `SyntaxContext::root`, then we can replace
73-
// this with just `span.edition()`. A
74-
// `SyntaxContext::root()` from the current crate will
75-
// have the edition of the current crate, and a
76-
// `SyntaxContext::root()` from a foreign crate will
77-
// have the edition of that crate (which we manually
78-
// retrieve via the `edition` parameter).
79-
if !span.from_expansion() {
80-
edition
81-
} else {
82-
span.edition()
83-
}
84-
};
66+
8567
let kind =
86-
token::NonterminalKind::from_symbol(fragment.name, edition)
87-
.unwrap_or_else(|| {
88-
let help = match fragment.name {
89-
sym::expr_2021 => {
90-
format!(
91-
"fragment specifier `expr_2021` \
92-
requires Rust 2021 or later\n\
93-
{VALID_FRAGMENT_NAMES_MSG}"
94-
)
95-
}
96-
_ if edition().at_least_rust_2021()
97-
&& features
98-
.expr_fragment_specifier_2024 =>
99-
{
100-
VALID_FRAGMENT_NAMES_MSG_2021.into()
101-
}
102-
_ => VALID_FRAGMENT_NAMES_MSG.into(),
103-
};
68+
token::NonterminalKind::from_symbol(fragment.name, || {
69+
// FIXME(#85708) - once we properly decode a foreign
70+
// crate's `SyntaxContext::root`, then we can replace
71+
// this with just `span.edition()`. A
72+
// `SyntaxContext::root()` from the current crate will
73+
// have the edition of the current crate, and a
74+
// `SyntaxContext::root()` from a foreign crate will
75+
// have the edition of that crate (which we manually
76+
// retrieve via the `edition` parameter).
77+
if !span.from_expansion() {
78+
edition
79+
} else {
80+
span.edition()
81+
}
82+
})
83+
.unwrap_or_else(
84+
|| {
10485
sess.dcx().emit_err(
10586
errors::InvalidFragmentSpecifier {
10687
span,
10788
fragment,
108-
help,
89+
help: VALID_FRAGMENT_NAMES_MSG.into(),
10990
},
11091
);
11192
token::NonterminalKind::Ident
112-
});
113-
if kind == token::NonterminalKind::Expr2021
114-
&& !features.expr_fragment_specifier_2024
115-
{
116-
rustc_session::parse::feature_err(
117-
sess,
118-
sym::expr_fragment_specifier_2024,
119-
span,
120-
"fragment specifier `expr_2021` is unstable",
121-
)
122-
.emit();
123-
}
93+
},
94+
);
12495
result.push(TokenTree::MetaVarDecl(span, ident, Some(kind)));
12596
continue;
12697
}

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ declare_features! (
458458
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
459459
/// Allows explicit tail calls via `become` expression.
460460
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
461-
/// Uses 2024 rules for matching `expr` fragments in macros. Also enables `expr_2021` fragment.
462-
(incomplete, expr_fragment_specifier_2024, "CURRENT_RUSTC_VERSION", Some(123742)),
463461
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
464462
/// for functions with varargs.
465463
(unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),

compiler/rustc_parse/src/parser/nonterminal.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,13 @@ impl<'a> Parser<'a> {
3636
}
3737

3838
match kind {
39-
NonterminalKind::Expr2021 => {
39+
NonterminalKind::Expr => {
4040
token.can_begin_expr()
4141
// This exception is here for backwards compatibility.
4242
&& !token.is_keyword(kw::Let)
4343
// This exception is here for backwards compatibility.
4444
&& !token.is_keyword(kw::Const)
4545
}
46-
NonterminalKind::Expr => {
47-
token.can_begin_expr()
48-
// This exception is here for backwards compatibility.
49-
&& !token.is_keyword(kw::Let)
50-
&& (token.span.edition().at_least_rust_2024() || !token.is_keyword(kw::Const))
51-
}
5246
NonterminalKind::Ty => token.can_begin_type(),
5347
NonterminalKind::Ident => get_macro_ident(token).is_some(),
5448
NonterminalKind::Literal => token.can_begin_literal_maybe_minus(),
@@ -149,9 +143,7 @@ impl<'a> Parser<'a> {
149143
})?)
150144
}
151145

152-
NonterminalKind::Expr | NonterminalKind::Expr2021 => {
153-
NtExpr(self.parse_expr_force_collect()?)
154-
}
146+
NonterminalKind::Expr => NtExpr(self.parse_expr_force_collect()?),
155147
NonterminalKind::Literal => {
156148
// The `:literal` matcher does not support attributes
157149
NtLiteral(self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?)

compiler/rustc_span/src/symbol.rs

-2
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,6 @@ symbols! {
782782
explicit_tail_calls,
783783
export_name,
784784
expr,
785-
expr_2021,
786-
expr_fragment_specifier_2024,
787785
extended_key_value_attributes,
788786
extended_varargs_abi_support,
789787
extern_absolute_paths,

tests/ui/macros/expr_2021_inline_const.edi2021.stderr

-32
This file was deleted.

tests/ui/macros/expr_2021_inline_const.edi2024.stderr

-17
This file was deleted.

tests/ui/macros/expr_2021_inline_const.rs

-23
This file was deleted.

tests/ui/macros/expr_2021_old_edition.rs

-13
This file was deleted.

tests/ui/macros/expr_2021_old_edition.stderr

-26
This file was deleted.

tests/ui/macros/feature-gate-expr_fragment_specifier_2024.rs

-11
This file was deleted.

tests/ui/macros/feature-gate-expr_fragment_specifier_2024.stderr

-13
This file was deleted.

0 commit comments

Comments
 (0)