@@ -100,17 +100,19 @@ fn invocation_fixtures(
100100 // So we just skip any error cases and try again
101101 let mut try_cnt = 0 ;
102102 loop {
103- let mut subtree = tt:: Subtree {
103+ let mut token_trees = Vec :: new ( ) ;
104+ for op in rule. lhs . iter ( ) {
105+ collect_from_op ( op, & mut token_trees, & mut seed) ;
106+ }
107+
108+ let subtree = tt:: Subtree {
104109 delimiter : tt:: Delimiter {
105110 open : DUMMY ,
106111 close : DUMMY ,
107112 kind : tt:: DelimiterKind :: Invisible ,
108113 } ,
109- token_trees : vec ! [ ] ,
114+ token_trees : token_trees . into_boxed_slice ( ) ,
110115 } ;
111- for op in rule. lhs . iter ( ) {
112- collect_from_op ( op, & mut subtree, & mut seed) ;
113- }
114116 if it. expand ( & subtree, |_| ( ) , true , DUMMY ) . err . is_none ( ) {
115117 res. push ( ( name. clone ( ) , subtree) ) ;
116118 break ;
@@ -127,45 +129,45 @@ fn invocation_fixtures(
127129
128130 fn collect_from_op (
129131 op : & Op < DummyTestSpanData > ,
130- parent : & mut tt:: Subtree < DummyTestSpanData > ,
132+ token_trees : & mut Vec < tt:: TokenTree < DummyTestSpanData > > ,
131133 seed : & mut usize ,
132134 ) {
133135 return match op {
134136 Op :: Var { kind, .. } => match kind. as_ref ( ) {
135- Some ( MetaVarKind :: Ident ) => parent . token_trees . push ( make_ident ( "foo" ) ) ,
136- Some ( MetaVarKind :: Ty ) => parent . token_trees . push ( make_ident ( "Foo" ) ) ,
137- Some ( MetaVarKind :: Tt ) => parent . token_trees . push ( make_ident ( "foo" ) ) ,
138- Some ( MetaVarKind :: Vis ) => parent . token_trees . push ( make_ident ( "pub" ) ) ,
139- Some ( MetaVarKind :: Pat ) => parent . token_trees . push ( make_ident ( "foo" ) ) ,
140- Some ( MetaVarKind :: Path ) => parent . token_trees . push ( make_ident ( "foo" ) ) ,
141- Some ( MetaVarKind :: Literal ) => parent . token_trees . push ( make_literal ( "1" ) ) ,
142- Some ( MetaVarKind :: Expr ) => parent . token_trees . push ( make_ident ( "foo" ) ) ,
137+ Some ( MetaVarKind :: Ident ) => token_trees. push ( make_ident ( "foo" ) ) ,
138+ Some ( MetaVarKind :: Ty ) => token_trees. push ( make_ident ( "Foo" ) ) ,
139+ Some ( MetaVarKind :: Tt ) => token_trees. push ( make_ident ( "foo" ) ) ,
140+ Some ( MetaVarKind :: Vis ) => token_trees. push ( make_ident ( "pub" ) ) ,
141+ Some ( MetaVarKind :: Pat ) => token_trees. push ( make_ident ( "foo" ) ) ,
142+ Some ( MetaVarKind :: Path ) => token_trees. push ( make_ident ( "foo" ) ) ,
143+ Some ( MetaVarKind :: Literal ) => token_trees. push ( make_literal ( "1" ) ) ,
144+ Some ( MetaVarKind :: Expr ) => token_trees. push ( make_ident ( "foo" ) ) ,
143145 Some ( MetaVarKind :: Lifetime ) => {
144- parent . token_trees . push ( make_punct ( '\'' ) ) ;
145- parent . token_trees . push ( make_ident ( "a" ) ) ;
146+ token_trees. push ( make_punct ( '\'' ) ) ;
147+ token_trees. push ( make_ident ( "a" ) ) ;
146148 }
147149 Some ( MetaVarKind :: Block ) => {
148- parent . token_trees . push ( make_subtree ( tt:: DelimiterKind :: Brace , None ) )
150+ token_trees. push ( make_subtree ( tt:: DelimiterKind :: Brace , None ) )
149151 }
150152 Some ( MetaVarKind :: Item ) => {
151- parent . token_trees . push ( make_ident ( "fn" ) ) ;
152- parent . token_trees . push ( make_ident ( "foo" ) ) ;
153- parent . token_trees . push ( make_subtree ( tt:: DelimiterKind :: Parenthesis , None ) ) ;
154- parent . token_trees . push ( make_subtree ( tt:: DelimiterKind :: Brace , None ) ) ;
153+ token_trees. push ( make_ident ( "fn" ) ) ;
154+ token_trees. push ( make_ident ( "foo" ) ) ;
155+ token_trees. push ( make_subtree ( tt:: DelimiterKind :: Parenthesis , None ) ) ;
156+ token_trees. push ( make_subtree ( tt:: DelimiterKind :: Brace , None ) ) ;
155157 }
156158 Some ( MetaVarKind :: Meta ) => {
157- parent . token_trees . push ( make_ident ( "foo" ) ) ;
158- parent . token_trees . push ( make_subtree ( tt:: DelimiterKind :: Parenthesis , None ) ) ;
159+ token_trees. push ( make_ident ( "foo" ) ) ;
160+ token_trees. push ( make_subtree ( tt:: DelimiterKind :: Parenthesis , None ) ) ;
159161 }
160162
161163 None => ( ) ,
162164 Some ( kind) => panic ! ( "Unhandled kind {kind:?}" ) ,
163165 } ,
164- Op :: Literal ( it) => parent . token_trees . push ( tt:: Leaf :: from ( it. clone ( ) ) . into ( ) ) ,
165- Op :: Ident ( it) => parent . token_trees . push ( tt:: Leaf :: from ( it. clone ( ) ) . into ( ) ) ,
166+ Op :: Literal ( it) => token_trees. push ( tt:: Leaf :: from ( it. clone ( ) ) . into ( ) ) ,
167+ Op :: Ident ( it) => token_trees. push ( tt:: Leaf :: from ( it. clone ( ) ) . into ( ) ) ,
166168 Op :: Punct ( puncts) => {
167169 for punct in puncts {
168- parent . token_trees . push ( tt:: Leaf :: from ( * punct) . into ( ) ) ;
170+ token_trees. push ( tt:: Leaf :: from ( * punct) . into ( ) ) ;
169171 }
170172 }
171173 Op :: Repeat { tokens, kind, separator } => {
@@ -177,20 +179,20 @@ fn invocation_fixtures(
177179 } ;
178180 for i in 0 ..cnt {
179181 for it in tokens. iter ( ) {
180- collect_from_op ( it, parent , seed) ;
182+ collect_from_op ( it, token_trees , seed) ;
181183 }
182184 if i + 1 != cnt {
183185 if let Some ( sep) = separator {
184186 match sep {
185187 Separator :: Literal ( it) => {
186- parent . token_trees . push ( tt:: Leaf :: Literal ( it. clone ( ) ) . into ( ) )
188+ token_trees. push ( tt:: Leaf :: Literal ( it. clone ( ) ) . into ( ) )
187189 }
188190 Separator :: Ident ( it) => {
189- parent . token_trees . push ( tt:: Leaf :: Ident ( it. clone ( ) ) . into ( ) )
191+ token_trees. push ( tt:: Leaf :: Ident ( it. clone ( ) ) . into ( ) )
190192 }
191193 Separator :: Puncts ( puncts) => {
192194 for it in puncts {
193- parent . token_trees . push ( tt:: Leaf :: Punct ( * it) . into ( ) )
195+ token_trees. push ( tt:: Leaf :: Punct ( * it) . into ( ) )
194196 }
195197 }
196198 } ;
@@ -199,11 +201,15 @@ fn invocation_fixtures(
199201 }
200202 }
201203 Op :: Subtree { tokens, delimiter } => {
202- let mut subtree = tt :: Subtree { delimiter : * delimiter , token_trees : Vec :: new ( ) } ;
204+ let mut subtree = Vec :: new ( ) ;
203205 tokens. iter ( ) . for_each ( |it| {
204206 collect_from_op ( it, & mut subtree, seed) ;
205207 } ) ;
206- parent. token_trees . push ( subtree. into ( ) ) ;
208+
209+ let subtree =
210+ tt:: Subtree { delimiter : * delimiter, token_trees : subtree. into_boxed_slice ( ) } ;
211+
212+ token_trees. push ( subtree. into ( ) ) ;
207213 }
208214 Op :: Ignore { .. } | Op :: Index { .. } | Op :: Count { .. } | Op :: Length { .. } => { }
209215 } ;
@@ -230,7 +236,7 @@ fn invocation_fixtures(
230236 ) -> tt:: TokenTree < DummyTestSpanData > {
231237 tt:: Subtree {
232238 delimiter : tt:: Delimiter { open : DUMMY , close : DUMMY , kind } ,
233- token_trees : token_trees. unwrap_or_default ( ) ,
239+ token_trees : token_trees. map ( Vec :: into_boxed_slice ) . unwrap_or_default ( ) ,
234240 }
235241 . into ( )
236242 }
0 commit comments