@@ -111,8 +111,8 @@ impl Match {
111111}
112112
113113/// Matching errors are added to the `Match`.
114- pub ( super ) fn match_ ( pattern : & MetaTemplate , input : & tt:: Subtree ) -> Match {
115- let mut res = match_loop ( pattern, input) ;
114+ pub ( super ) fn match_ ( pattern : & MetaTemplate , input : & tt:: Subtree , is_2021 : bool ) -> Match {
115+ let mut res = match_loop ( pattern, input, is_2021 ) ;
116116 res. bound_count = count ( res. bindings . bindings ( ) ) ;
117117 return res;
118118
@@ -354,6 +354,7 @@ struct MatchState<'t> {
354354/// - `eof_items`: the set of items that would be valid if this was the EOF.
355355/// - `bb_items`: the set of items that are waiting for the black-box parser.
356356/// - `error_items`: the set of items in errors, used for error-resilient parsing
357+ #[ inline]
357358fn match_loop_inner < ' t > (
358359 src : TtIter < ' t > ,
359360 stack : & [ TtIter < ' t > ] ,
@@ -364,6 +365,7 @@ fn match_loop_inner<'t>(
364365 next_items : & mut Vec < MatchState < ' t > > ,
365366 eof_items : & mut SmallVec < [ MatchState < ' t > ; 1 ] > ,
366367 error_items : & mut SmallVec < [ MatchState < ' t > ; 1 ] > ,
368+ is_2021 : bool ,
367369) {
368370 macro_rules! try_push {
369371 ( $items: expr, $it: expr) => {
@@ -474,7 +476,7 @@ fn match_loop_inner<'t>(
474476 OpDelimited :: Op ( Op :: Var { kind, name, .. } ) => {
475477 if let & Some ( kind) = kind {
476478 let mut fork = src. clone ( ) ;
477- let match_res = match_meta_var ( kind, & mut fork) ;
479+ let match_res = match_meta_var ( kind, & mut fork, is_2021 ) ;
478480 match match_res. err {
479481 None => {
480482 // Some meta variables are optional (e.g. vis)
@@ -583,7 +585,7 @@ fn match_loop_inner<'t>(
583585 }
584586}
585587
586- fn match_loop ( pattern : & MetaTemplate , src : & tt:: Subtree ) -> Match {
588+ fn match_loop ( pattern : & MetaTemplate , src : & tt:: Subtree , is_2021 : bool ) -> Match {
587589 let mut src = TtIter :: new ( src) ;
588590 let mut stack: SmallVec < [ TtIter < ' _ > ; 1 ] > = SmallVec :: new ( ) ;
589591 let mut res = Match :: default ( ) ;
@@ -622,6 +624,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
622624 & mut next_items,
623625 & mut eof_items,
624626 & mut error_items,
627+ is_2021,
625628 ) ;
626629 stdx:: always!( cur_items. is_empty( ) ) ;
627630
@@ -731,14 +734,17 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
731734 }
732735}
733736
734- fn match_meta_var ( kind : MetaVarKind , input : & mut TtIter < ' _ > ) -> ExpandResult < Option < Fragment > > {
737+ fn match_meta_var (
738+ kind : MetaVarKind ,
739+ input : & mut TtIter < ' _ > ,
740+ is_2021 : bool ,
741+ ) -> ExpandResult < Option < Fragment > > {
735742 let fragment = match kind {
736743 MetaVarKind :: Path => parser:: PrefixEntryPoint :: Path ,
737744 MetaVarKind :: Ty => parser:: PrefixEntryPoint :: Ty ,
738- // FIXME: These two should actually behave differently depending on the edition.
739- //
740- // https://doc.rust-lang.org/edition-guide/rust-2021/or-patterns-macro-rules.html
741- MetaVarKind :: Pat | MetaVarKind :: PatParam => parser:: PrefixEntryPoint :: Pat ,
745+ MetaVarKind :: Pat if is_2021 => parser:: PrefixEntryPoint :: PatTop ,
746+ MetaVarKind :: Pat => parser:: PrefixEntryPoint :: Pat ,
747+ MetaVarKind :: PatParam => parser:: PrefixEntryPoint :: Pat ,
742748 MetaVarKind :: Stmt => parser:: PrefixEntryPoint :: Stmt ,
743749 MetaVarKind :: Block => parser:: PrefixEntryPoint :: Block ,
744750 MetaVarKind :: Meta => parser:: PrefixEntryPoint :: MetaItem ,
0 commit comments