@@ -437,11 +437,12 @@ fn match_loop_inner<'t>(
437437 let mut new_item = item. clone ( ) ;
438438 new_item. bindings = bindings_builder. copy ( & new_item. bindings ) ;
439439 new_item. dot . next ( ) ;
440- let mut vars = Vec :: new ( ) ;
441- collect_vars ( & mut vars, tokens) ;
442- for var in vars {
443- bindings_builder. push_empty ( & mut new_item. bindings , & var) ;
444- }
440+ collect_vars (
441+ & mut |s| {
442+ bindings_builder. push_empty ( & mut new_item. bindings , & s) ;
443+ } ,
444+ tokens,
445+ ) ;
445446 cur_items. push ( new_item) ;
446447 }
447448 cur_items. push ( MatchState {
@@ -729,17 +730,16 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
729730 input. expect_fragment ( fragment) . map ( |it| it. map ( Fragment :: Tokens ) )
730731}
731732
732- fn collect_vars ( buf : & mut Vec < SmolStr > , pattern : & MetaTemplate ) {
733+ fn collect_vars ( collector_fun : & mut impl FnMut ( SmolStr ) , pattern : & MetaTemplate ) {
733734 for op in pattern. iter ( ) {
734735 match op {
735- Op :: Var { name, .. } => buf . push ( name. clone ( ) ) ,
736+ Op :: Var { name, .. } => collector_fun ( name. clone ( ) ) ,
736737 Op :: Leaf ( _) => ( ) ,
737- Op :: Subtree { tokens, .. } => collect_vars ( buf , tokens) ,
738- Op :: Repeat { tokens, .. } => collect_vars ( buf , tokens) ,
738+ Op :: Subtree { tokens, .. } => collect_vars ( collector_fun , tokens) ,
739+ Op :: Repeat { tokens, .. } => collect_vars ( collector_fun , tokens) ,
739740 }
740741 }
741742}
742-
743743impl MetaTemplate {
744744 fn iter_delimited < ' a > ( & ' a self , delimited : Option < & ' a tt:: Delimiter > ) -> OpDelimitedIter < ' a > {
745745 OpDelimitedIter { inner : & self . 0 , idx : 0 , delimited }
0 commit comments