@@ -224,7 +224,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
224
224
let ( expansion, mut invocations) = self . collect_invocations ( expansion) ;
225
225
invocations. reverse ( ) ;
226
226
227
- let mut expansions = vec ! [ vec! [ ( 0 , expansion ) ] ] ;
227
+ let mut expansions = Vec :: new ( ) ;
228
228
while let Some ( invoc) = invocations. pop ( ) {
229
229
let ExpansionData { depth, mark, .. } = invoc. expansion_data ;
230
230
self . cx . current_expansion = invoc. expansion_data . clone ( ) ;
@@ -236,13 +236,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
236
236
None => invoc. expansion_kind . dummy ( invoc. span ( ) ) ,
237
237
} ;
238
238
239
- self . cx . current_expansion . depth = depth + 1 ;
240
239
let ( expansion, new_invocations) = self . collect_invocations ( expansion) ;
241
240
242
- if expansions. len ( ) == depth {
241
+ if expansions. len ( ) < depth {
243
242
expansions. push ( Vec :: new ( ) ) ;
244
243
}
245
- expansions[ depth] . push ( ( mark. as_u32 ( ) , expansion) ) ;
244
+ expansions[ depth - 1 ] . push ( ( mark. as_u32 ( ) , expansion) ) ;
246
245
if !self . cx . ecfg . single_step {
247
246
invocations. extend ( new_invocations. into_iter ( ) . rev ( ) ) ;
248
247
}
@@ -253,12 +252,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
253
252
let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
254
253
while let Some ( expansions) = expansions. pop ( ) {
255
254
for ( mark, expansion) in expansions. into_iter ( ) . rev ( ) {
256
- let expansion = expansion. fold_with ( & mut placeholder_expander) ;
257
255
placeholder_expander. add ( ast:: NodeId :: from_u32 ( mark) , expansion) ;
258
256
}
259
257
}
260
258
261
- placeholder_expander . remove ( ast :: NodeId :: from_u32 ( 0 ) )
259
+ expansion . fold_with ( & mut placeholder_expander )
262
260
}
263
261
264
262
fn collect_invocations ( & mut self , expansion : Expansion ) -> ( Expansion , Vec < Invocation > ) {
@@ -541,7 +539,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
541
539
self . invocations . push ( Invocation {
542
540
kind : kind,
543
541
expansion_kind : expansion_kind,
544
- expansion_data : ExpansionData { mark : mark, ..self . cx . current_expansion . clone ( ) } ,
542
+ expansion_data : ExpansionData {
543
+ mark : mark,
544
+ depth : self . cx . current_expansion . depth + 1 ,
545
+ ..self . cx . current_expansion . clone ( )
546
+ } ,
545
547
} ) ;
546
548
placeholder ( expansion_kind, ast:: NodeId :: from_u32 ( mark. as_u32 ( ) ) )
547
549
}
0 commit comments