@@ -69,7 +69,7 @@ use tt::{iter::TtIter, DelimSpan};
69
69
use crate :: {
70
70
expander:: { Binding , Bindings , ExpandResult , Fragment } ,
71
71
expect_fragment,
72
- parser:: { MetaVarKind , Op , RepeatKind , Separator } ,
72
+ parser:: { ExprKind , MetaVarKind , Op , RepeatKind , Separator } ,
73
73
ExpandError , ExpandErrorKind , MetaTemplate , ValueResult ,
74
74
} ;
75
75
@@ -769,23 +769,28 @@ fn match_meta_var(
769
769
it. map ( |it| tt:: TokenTree :: subtree_or_wrap ( it, delim_span) ) . map ( Fragment :: Path )
770
770
} ) ;
771
771
}
772
- MetaVarKind :: Expr => {
773
- // `expr` should not match underscores, let expressions, or inline const. The latter
774
- // two are for [backwards compatibility][0].
772
+ MetaVarKind :: Expr ( expr) => {
773
+ // `expr_2021` should not match underscores, let expressions, or inline const.
774
+ // The latter two are for [backwards compatibility][0].
775
+ // And `expr` also should not contain let expressions but may contain the other two
776
+ // since `Edition2024`.
775
777
// HACK: Macro expansion should not be done using "rollback and try another alternative".
776
778
// rustc [explicitly checks the next token][1].
777
779
// [0]: https://github.com/rust-lang/rust/issues/86730
778
780
// [1]: https://github.com/rust-lang/rust/blob/f0c4da499/compiler/rustc_expand/src/mbe/macro_parser.rs#L576
779
781
match input. peek_n ( 0 ) {
780
- Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( it) ) )
781
- if it. sym == sym:: underscore
782
- || it. sym == sym:: let_
783
- || it. sym == sym:: const_ =>
784
- {
785
- return ExpandResult :: only_err ( ExpandError :: new (
786
- it. span ,
787
- ExpandErrorKind :: NoMatchingRule ,
788
- ) )
782
+ Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( it) ) ) => {
783
+ let is_err = if matches ! ( expr, ExprKind :: Expr2021 ) {
784
+ it. sym == sym:: underscore || it. sym == sym:: let_ || it. sym == sym:: const_
785
+ } else {
786
+ it. sym == sym:: let_
787
+ } ;
788
+ if is_err {
789
+ return ExpandResult :: only_err ( ExpandError :: new (
790
+ it. span ,
791
+ ExpandErrorKind :: NoMatchingRule ,
792
+ ) ) ;
793
+ }
789
794
}
790
795
_ => { }
791
796
} ;
0 commit comments