@@ -69,7 +69,7 @@ use tt::{iter::TtIter, DelimSpan};
6969use crate :: {
7070 expander:: { Binding , Bindings , ExpandResult , Fragment } ,
7171 expect_fragment,
72- parser:: { MetaVarKind , Op , RepeatKind , Separator } ,
72+ parser:: { ExprKind , MetaVarKind , Op , RepeatKind , Separator } ,
7373 ExpandError , ExpandErrorKind , MetaTemplate , ValueResult ,
7474} ;
7575
@@ -769,23 +769,28 @@ fn match_meta_var(
769769 it. map ( |it| tt:: TokenTree :: subtree_or_wrap ( it, delim_span) ) . map ( Fragment :: Path )
770770 } ) ;
771771 }
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`.
775777 // HACK: Macro expansion should not be done using "rollback and try another alternative".
776778 // rustc [explicitly checks the next token][1].
777779 // [0]: https://github.com/rust-lang/rust/issues/86730
778780 // [1]: https://github.com/rust-lang/rust/blob/f0c4da499/compiler/rustc_expand/src/mbe/macro_parser.rs#L576
779781 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+ }
789794 }
790795 _ => { }
791796 } ;
0 commit comments