Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/expander/matcher.rs')
-rw-r--r--crates/mbe/src/expander/matcher.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index e69d7d14e2..90f56cc31d 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -69,7 +69,7 @@ use tt::{iter::TtIter, DelimSpan};
use crate::{
expander::{Binding, Bindings, ExpandResult, Fragment},
expect_fragment,
- parser::{MetaVarKind, Op, RepeatKind, Separator},
+ parser::{ExprKind, MetaVarKind, Op, RepeatKind, Separator},
ExpandError, ExpandErrorKind, MetaTemplate, ValueResult,
};
@@ -769,23 +769,28 @@ fn match_meta_var(
it.map(|it| tt::TokenTree::subtree_or_wrap(it, delim_span)).map(Fragment::Path)
});
}
- MetaVarKind::Expr => {
- // `expr` should not match underscores, let expressions, or inline const. The latter
- // two are for [backwards compatibility][0].
+ MetaVarKind::Expr(expr) => {
+ // `expr_2021` should not match underscores, let expressions, or inline const.
+ // The latter two are for [backwards compatibility][0].
+ // And `expr` also should not contain let expressions but may contain the other two
+ // since `Edition2024`.
// HACK: Macro expansion should not be done using "rollback and try another alternative".
// rustc [explicitly checks the next token][1].
// [0]: https://github.com/rust-lang/rust/issues/86730
// [1]: https://github.com/rust-lang/rust/blob/f0c4da499/compiler/rustc_expand/src/mbe/macro_parser.rs#L576
match input.peek_n(0) {
- Some(tt::TokenTree::Leaf(tt::Leaf::Ident(it)))
- if it.sym == sym::underscore
- || it.sym == sym::let_
- || it.sym == sym::const_ =>
- {
- return ExpandResult::only_err(ExpandError::new(
- it.span,
- ExpandErrorKind::NoMatchingRule,
- ))
+ Some(tt::TokenTree::Leaf(tt::Leaf::Ident(it))) => {
+ let is_err = if matches!(expr, ExprKind::Expr2021) {
+ it.sym == sym::underscore || it.sym == sym::let_ || it.sym == sym::const_
+ } else {
+ it.sym == sym::let_
+ };
+ if is_err {
+ return ExpandResult::only_err(ExpandError::new(
+ it.span,
+ ExpandErrorKind::NoMatchingRule,
+ ));
+ }
}
_ => {}
};