@@ -208,14 +208,23 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
208
208
}
209
209
210
210
fn collect_invocations ( & mut self , expansion : Expansion ) -> ( Expansion , Vec < Invocation > ) {
211
- let expansion = expansion. fold_with ( & mut StripUnconfigured {
212
- config : & self . cx . cfg ,
213
- should_test : self . cx . ecfg . should_test ,
214
- sess : self . cx . parse_sess ,
215
- features : self . cx . ecfg . features ,
216
- } ) ;
217
- let mut collector = InvocationCollector { cx : self . cx , invocations : Vec :: new ( ) } ;
218
- ( expansion. fold_with ( & mut collector) , collector. invocations )
211
+ let crate_config = mem:: replace ( & mut self . cx . cfg , Vec :: new ( ) ) ;
212
+ let result = {
213
+ let mut collector = InvocationCollector {
214
+ cfg : StripUnconfigured {
215
+ config : & crate_config,
216
+ should_test : self . cx . ecfg . should_test ,
217
+ sess : self . cx . parse_sess ,
218
+ features : self . cx . ecfg . features ,
219
+ } ,
220
+ cx : self . cx ,
221
+ invocations : Vec :: new ( ) ,
222
+ } ;
223
+ ( expansion. fold_with ( & mut collector) , collector. invocations )
224
+ } ;
225
+
226
+ self . cx . cfg = crate_config;
227
+ result
219
228
}
220
229
221
230
fn expand_invoc ( & mut self , invoc : Invocation ) -> Expansion {
@@ -403,6 +412,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
403
412
404
413
struct InvocationCollector < ' a , ' b : ' a > {
405
414
cx : & ' a mut ExtCtxt < ' b > ,
415
+ cfg : StripUnconfigured < ' a > ,
406
416
invocations : Vec < Invocation > ,
407
417
}
408
418
@@ -479,7 +489,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
479
489
480
490
impl < ' a , ' b > Folder for InvocationCollector < ' a , ' b > {
481
491
fn fold_expr ( & mut self , expr : P < ast:: Expr > ) -> P < ast:: Expr > {
482
- let expr = expr. unwrap ( ) ;
492
+ let mut expr = self . cfg . configure_expr ( expr) . unwrap ( ) ;
493
+ expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
494
+
483
495
if let ast:: ExprKind :: Mac ( mac) = expr. node {
484
496
self . collect_bang ( mac, expr. attrs . into ( ) , expr. span , ExpansionKind :: Expr ) . make_expr ( )
485
497
} else {
@@ -488,7 +500,12 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
488
500
}
489
501
490
502
fn fold_opt_expr ( & mut self , expr : P < ast:: Expr > ) -> Option < P < ast:: Expr > > {
491
- let expr = expr. unwrap ( ) ;
503
+ let mut expr = match self . cfg . configure ( expr) {
504
+ Some ( expr) => expr. unwrap ( ) ,
505
+ None => return None ,
506
+ } ;
507
+ expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
508
+
492
509
if let ast:: ExprKind :: Mac ( mac) = expr. node {
493
510
self . collect_bang ( mac, expr. attrs . into ( ) , expr. span , ExpansionKind :: OptExpr )
494
511
. make_opt_expr ( )
@@ -511,6 +528,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
511
528
}
512
529
513
530
fn fold_stmt ( & mut self , stmt : ast:: Stmt ) -> SmallVector < ast:: Stmt > {
531
+ let stmt = match self . cfg . configure_stmt ( stmt) {
532
+ Some ( stmt) => stmt,
533
+ None => return SmallVector :: zero ( ) ,
534
+ } ;
535
+
514
536
let ( mac, style, attrs) = match stmt. node {
515
537
StmtKind :: Mac ( mac) => mac. unwrap ( ) ,
516
538
_ => return noop_fold_stmt ( stmt, self ) ,
@@ -540,6 +562,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
540
562
}
541
563
542
564
fn fold_item ( & mut self , item : P < ast:: Item > ) -> SmallVector < P < ast:: Item > > {
565
+ let item = match self . cfg . configure ( item) {
566
+ Some ( item) => item,
567
+ None => return SmallVector :: zero ( ) ,
568
+ } ;
569
+
543
570
let ( item, attr) = self . classify_item ( item) ;
544
571
if let Some ( attr) = attr {
545
572
let item = Annotatable :: Item ( item) ;
@@ -610,6 +637,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
610
637
}
611
638
612
639
fn fold_trait_item ( & mut self , item : ast:: TraitItem ) -> SmallVector < ast:: TraitItem > {
640
+ let item = match self . cfg . configure ( item) {
641
+ Some ( item) => item,
642
+ None => return SmallVector :: zero ( ) ,
643
+ } ;
644
+
613
645
let ( item, attr) = self . classify_item ( item) ;
614
646
if let Some ( attr) = attr {
615
647
let item = Annotatable :: TraitItem ( P ( item) ) ;
@@ -626,6 +658,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
626
658
}
627
659
628
660
fn fold_impl_item ( & mut self , item : ast:: ImplItem ) -> SmallVector < ast:: ImplItem > {
661
+ let item = match self . cfg . configure ( item) {
662
+ Some ( item) => item,
663
+ None => return SmallVector :: zero ( ) ,
664
+ } ;
665
+
629
666
let ( item, attr) = self . classify_item ( item) ;
630
667
if let Some ( attr) = attr {
631
668
let item = Annotatable :: ImplItem ( P ( item) ) ;
@@ -653,6 +690,16 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
653
690
_ => unreachable ! ( ) ,
654
691
}
655
692
}
693
+
694
+ fn fold_foreign_mod ( & mut self , foreign_mod : ast:: ForeignMod ) -> ast:: ForeignMod {
695
+ let foreign_mod = self . cfg . configure_foreign_mod ( foreign_mod) ;
696
+ noop_fold_foreign_mod ( foreign_mod, self )
697
+ }
698
+
699
+ fn fold_item_kind ( & mut self , item : ast:: ItemKind ) -> ast:: ItemKind {
700
+ let item = self . cfg . configure_item_kind ( item) ;
701
+ noop_fold_item_kind ( item, self )
702
+ }
656
703
}
657
704
658
705
pub struct ExpansionConfig < ' feat > {
0 commit comments