Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 56840d9

Browse files
committed
Revert "Apply code review suggestions"
This reverts commit f364011.
1 parent ba02e65 commit 56840d9

File tree

7 files changed

+31
-57
lines changed

7 files changed

+31
-57
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ impl NonterminalKind {
912912
},
913913
sym::pat_param => NonterminalKind::PatParam { inferred: false },
914914
sym::expr => NonterminalKind::Expr,
915-
sym::expr_2021 if edition().at_least_rust_2021() => NonterminalKind::Expr2021,
915+
sym::expr_2021 if edition() >= Edition::Edition2021 => NonterminalKind::Expr2021,
916916
sym::ty => NonterminalKind::Ty,
917917
sym::ident => NonterminalKind::Ident,
918918
sym::lifetime => NonterminalKind::Lifetime,

compiler/rustc_expand/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ expand_explain_doc_comment_inner =
4747
expand_explain_doc_comment_outer =
4848
outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
4949
50+
expand_expr_2021_is_experimental =
51+
expr_2021 is experimental
52+
5053
expand_expr_repeat_no_syntax_vars =
5154
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
5255

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 23 additions & 46 deletions
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,59 +63,40 @@ 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-
});
93+
},
94+
);
11395
if kind == token::NonterminalKind::Expr2021
11496
&& !features.expr_fragment_specifier_2024
11597
{
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();
98+
sess.dcx()
99+
.emit_err(errors::Expr2021IsExperimental { span });
123100
}
124101
result.push(TokenTree::MetaVarDecl(span, ident, Some(kind)));
125102
continue;

tests/ui/macros/expr_2021_old_edition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ compile-flags: --edition=2018
22

3-
// This test ensures that expr_2021 is not allowed on pre-2021 editions
3+
// This test ensures that expr_2021 is not allowed on pre-2024 editions
44

55
macro_rules! m {
66
($e:expr_2021) => { //~ ERROR: invalid fragment specifier `expr_2021`

tests/ui/macros/expr_2021_old_edition.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error: invalid fragment specifier `expr_2021`
44
LL | ($e:expr_2021) => {
55
| ^^^^^^^^^^^^
66
|
7-
= help: fragment specifier `expr_2021` requires Rust 2021 or later
8-
valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
7+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
98

109
error: no rules expected the token `(`
1110
--> $DIR/expr_2021_old_edition.rs:12:8

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ compile-flags: --edition=2024 -Z unstable-options
22

33
macro_rules! m {
4-
($e:expr_2021) => { //~ ERROR: fragment specifier `expr_2021` is unstable
4+
($e:expr_2021) => { //~ ERROR: expr_2021 is experimental
55
$e
66
};
77
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
error[E0658]: fragment specifier `expr_2021` is unstable
1+
error: expr_2021 is experimental
22
--> $DIR/feature-gate-expr_fragment_specifier_2024.rs:4:6
33
|
44
LL | ($e:expr_2021) => {
55
| ^^^^^^^^^^^^
6-
|
7-
= note: see issue #123742 <https://github.com/rust-lang/rust/issues/123742> for more information
8-
= help: add `#![feature(expr_fragment_specifier_2024)]` to the crate attributes to enable
9-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
106

117
error: aborting due to 1 previous error
128

13-
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)