@@ -175,16 +175,16 @@ pub struct MacroExpander<'a, 'b:'a> {
175
175
pub cx : & ' a mut ExtCtxt < ' b > ,
176
176
pub single_step : bool ,
177
177
pub keep_macs : bool ,
178
+ monotonic : bool , // c.f. `cx.monotonic_expander()`
178
179
}
179
180
180
181
impl < ' a , ' b > MacroExpander < ' a , ' b > {
181
- pub fn new ( cx : & ' a mut ExtCtxt < ' b > ,
182
- single_step : bool ,
183
- keep_macs : bool ) -> MacroExpander < ' a , ' b > {
182
+ pub fn new ( cx : & ' a mut ExtCtxt < ' b > , monotonic : bool ) -> Self {
184
183
MacroExpander {
185
184
cx : cx,
186
- single_step : single_step,
187
- keep_macs : keep_macs
185
+ monotonic : monotonic,
186
+ single_step : false ,
187
+ keep_macs : false ,
188
188
}
189
189
}
190
190
@@ -245,7 +245,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
245
245
246
246
self . cx . current_expansion = orig_expansion_data;
247
247
248
- let mut placeholder_expander = PlaceholderExpander :: new ( self . cx ) ;
248
+ let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
249
249
while let Some ( expansions) = expansions. pop ( ) {
250
250
for ( mark, expansion) in expansions. into_iter ( ) . rev ( ) {
251
251
let expansion = expansion. fold_with ( & mut placeholder_expander) ;
@@ -268,6 +268,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
268
268
} ,
269
269
cx : self . cx ,
270
270
invocations : Vec :: new ( ) ,
271
+ monotonic : self . monotonic ,
271
272
} ;
272
273
( expansion. fold_with ( & mut collector) , collector. invocations )
273
274
} ;
@@ -450,6 +451,7 @@ struct InvocationCollector<'a, 'b: 'a> {
450
451
cx : & ' a mut ExtCtxt < ' b > ,
451
452
cfg : StripUnconfigured < ' a > ,
452
453
invocations : Vec < Invocation > ,
454
+ monotonic : bool ,
453
455
}
454
456
455
457
macro_rules! fully_configure {
@@ -709,8 +711,12 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
709
711
}
710
712
711
713
fn new_id ( & mut self , id : ast:: NodeId ) -> ast:: NodeId {
712
- assert_eq ! ( id, ast:: DUMMY_NODE_ID ) ;
713
- self . cx . resolver . next_node_id ( )
714
+ if self . monotonic {
715
+ assert_eq ! ( id, ast:: DUMMY_NODE_ID ) ;
716
+ self . cx . resolver . next_node_id ( )
717
+ } else {
718
+ id
719
+ }
714
720
}
715
721
}
716
722
@@ -763,7 +769,7 @@ pub fn expand_crate(cx: &mut ExtCtxt,
763
769
user_exts : Vec < NamedSyntaxExtension > ,
764
770
c : Crate ) -> Crate {
765
771
cx. initialize ( user_exts, & c) ;
766
- cx. expander ( ) . expand_crate ( c)
772
+ cx. monotonic_expander ( ) . expand_crate ( c)
767
773
}
768
774
769
775
// Expands crate using supplied MacroExpander - allows for
0 commit comments