@@ -26,7 +26,6 @@ use ptr::P;
26
26
use tokenstream:: TokenTree ;
27
27
use util:: small_vector:: SmallVector ;
28
28
29
- use std:: collections:: HashMap ;
30
29
use std:: mem;
31
30
use std:: path:: PathBuf ;
32
31
use std:: rc:: Rc ;
@@ -182,10 +181,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
182
181
183
182
// Fully expand all the invocations in `expansion`.
184
183
fn expand ( & mut self , expansion : Expansion ) -> Expansion {
184
+ self . cx . recursion_count = 0 ;
185
185
let ( expansion, mut invocations) = self . collect_invocations ( expansion) ;
186
186
invocations. reverse ( ) ;
187
187
188
- let mut expansions = HashMap :: new ( ) ;
188
+ let mut expansions = vec ! [ vec! [ ( 0 , expansion ) ] ] ;
189
189
while let Some ( invoc) = invocations. pop ( ) {
190
190
let Invocation { mark, module, depth, backtrace, .. } = invoc;
191
191
self . cx . syntax_env . current_module = module;
@@ -198,13 +198,24 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
198
198
self . cx . recursion_count = depth + 1 ;
199
199
let ( expansion, new_invocations) = self . collect_invocations ( expansion) ;
200
200
201
- expansions. insert ( mark. as_u32 ( ) , expansion) ;
201
+ if expansions. len ( ) == depth {
202
+ expansions. push ( Vec :: new ( ) ) ;
203
+ }
204
+ expansions[ depth] . push ( ( mark. as_u32 ( ) , expansion) ) ;
202
205
if !self . single_step {
203
206
invocations. extend ( new_invocations. into_iter ( ) . rev ( ) ) ;
204
207
}
205
208
}
206
209
207
- expansion. fold_with ( & mut PlaceholderExpander :: new ( expansions) )
210
+ let mut placeholder_expander = PlaceholderExpander :: new ( ) ;
211
+ while let Some ( expansions) = expansions. pop ( ) {
212
+ for ( mark, expansion) in expansions. into_iter ( ) . rev ( ) {
213
+ let expansion = expansion. fold_with ( & mut placeholder_expander) ;
214
+ placeholder_expander. add ( mark, expansion) ;
215
+ }
216
+ }
217
+
218
+ placeholder_expander. remove ( 0 )
208
219
}
209
220
210
221
fn collect_invocations ( & mut self , expansion : Expansion ) -> ( Expansion , Vec < Invocation > ) {
0 commit comments