@@ -111,8 +111,8 @@ impl Match {
111
111
}
112
112
113
113
/// 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 ) ;
116
116
res. bound_count = count ( res. bindings . bindings ( ) ) ;
117
117
return res;
118
118
@@ -354,6 +354,7 @@ struct MatchState<'t> {
354
354
/// - `eof_items`: the set of items that would be valid if this was the EOF.
355
355
/// - `bb_items`: the set of items that are waiting for the black-box parser.
356
356
/// - `error_items`: the set of items in errors, used for error-resilient parsing
357
+ #[ inline]
357
358
fn match_loop_inner < ' t > (
358
359
src : TtIter < ' t > ,
359
360
stack : & [ TtIter < ' t > ] ,
@@ -364,6 +365,7 @@ fn match_loop_inner<'t>(
364
365
next_items : & mut Vec < MatchState < ' t > > ,
365
366
eof_items : & mut SmallVec < [ MatchState < ' t > ; 1 ] > ,
366
367
error_items : & mut SmallVec < [ MatchState < ' t > ; 1 ] > ,
368
+ is_2021 : bool ,
367
369
) {
368
370
macro_rules! try_push {
369
371
( $items: expr, $it: expr) => {
@@ -474,7 +476,7 @@ fn match_loop_inner<'t>(
474
476
OpDelimited :: Op ( Op :: Var { kind, name, .. } ) => {
475
477
if let & Some ( kind) = kind {
476
478
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 ) ;
478
480
match match_res. err {
479
481
None => {
480
482
// Some meta variables are optional (e.g. vis)
@@ -583,7 +585,7 @@ fn match_loop_inner<'t>(
583
585
}
584
586
}
585
587
586
- fn match_loop ( pattern : & MetaTemplate , src : & tt:: Subtree ) -> Match {
588
+ fn match_loop ( pattern : & MetaTemplate , src : & tt:: Subtree , is_2021 : bool ) -> Match {
587
589
let mut src = TtIter :: new ( src) ;
588
590
let mut stack: SmallVec < [ TtIter < ' _ > ; 1 ] > = SmallVec :: new ( ) ;
589
591
let mut res = Match :: default ( ) ;
@@ -622,6 +624,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
622
624
& mut next_items,
623
625
& mut eof_items,
624
626
& mut error_items,
627
+ is_2021,
625
628
) ;
626
629
stdx:: always!( cur_items. is_empty( ) ) ;
627
630
@@ -731,14 +734,17 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
731
734
}
732
735
}
733
736
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 > > {
735
742
let fragment = match kind {
736
743
MetaVarKind :: Path => parser:: PrefixEntryPoint :: Path ,
737
744
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 ,
742
748
MetaVarKind :: Stmt => parser:: PrefixEntryPoint :: Stmt ,
743
749
MetaVarKind :: Block => parser:: PrefixEntryPoint :: Block ,
744
750
MetaVarKind :: Meta => parser:: PrefixEntryPoint :: MetaItem ,
0 commit comments