@@ -175,16 +175,16 @@ pub struct MacroExpander<'a, 'b:'a> {
175175 pub cx : & ' a mut ExtCtxt < ' b > ,
176176 pub single_step : bool ,
177177 pub keep_macs : bool ,
178+ monotonic : bool , // c.f. `cx.monotonic_expander()`
178179}
179180
180181impl < ' 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 {
184183 MacroExpander {
185184 cx : cx,
186- single_step : single_step,
187- keep_macs : keep_macs
185+ monotonic : monotonic,
186+ single_step : false ,
187+ keep_macs : false ,
188188 }
189189 }
190190
@@ -245,7 +245,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
245245
246246 self . cx . current_expansion = orig_expansion_data;
247247
248- let mut placeholder_expander = PlaceholderExpander :: new ( self . cx ) ;
248+ let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
249249 while let Some ( expansions) = expansions. pop ( ) {
250250 for ( mark, expansion) in expansions. into_iter ( ) . rev ( ) {
251251 let expansion = expansion. fold_with ( & mut placeholder_expander) ;
@@ -268,6 +268,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
268268 } ,
269269 cx : self . cx ,
270270 invocations : Vec :: new ( ) ,
271+ monotonic : self . monotonic ,
271272 } ;
272273 ( expansion. fold_with ( & mut collector) , collector. invocations )
273274 } ;
@@ -450,6 +451,7 @@ struct InvocationCollector<'a, 'b: 'a> {
450451 cx : & ' a mut ExtCtxt < ' b > ,
451452 cfg : StripUnconfigured < ' a > ,
452453 invocations : Vec < Invocation > ,
454+ monotonic : bool ,
453455}
454456
455457macro_rules! fully_configure {
@@ -709,8 +711,12 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
709711 }
710712
711713 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+ }
714720 }
715721}
716722
@@ -763,7 +769,7 @@ pub fn expand_crate(cx: &mut ExtCtxt,
763769 user_exts : Vec < NamedSyntaxExtension > ,
764770 c : Crate ) -> Crate {
765771 cx. initialize ( user_exts, & c) ;
766- cx. expander ( ) . expand_crate ( c)
772+ cx. monotonic_expander ( ) . expand_crate ( c)
767773}
768774
769775// Expands crate using supplied MacroExpander - allows for
0 commit comments