@@ -308,7 +308,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
308308 err. emit ( ) ;
309309 }
310310
311- let item = item
311+ let item = self . fully_configure ( item)
312312 . map_attrs ( |mut attrs| { attrs. retain ( |a| a. path != "derive" ) ; attrs } ) ;
313313 let item_with_markers =
314314 add_derived_markers ( & mut self . cx , item. span ( ) , & traits, item. clone ( ) ) ;
@@ -400,6 +400,27 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
400400 result
401401 }
402402
403+ fn fully_configure ( & mut self , item : Annotatable ) -> Annotatable {
404+ let mut cfg = StripUnconfigured {
405+ should_test : self . cx . ecfg . should_test ,
406+ sess : self . cx . parse_sess ,
407+ features : self . cx . ecfg . features ,
408+ } ;
409+ // Since the item itself has already been configured by the InvocationCollector,
410+ // we know that fold result vector will contain exactly one element
411+ match item {
412+ Annotatable :: Item ( item) => {
413+ Annotatable :: Item ( cfg. fold_item ( item) . pop ( ) . unwrap ( ) )
414+ }
415+ Annotatable :: TraitItem ( item) => {
416+ Annotatable :: TraitItem ( item. map ( |item| cfg. fold_trait_item ( item) . pop ( ) . unwrap ( ) ) )
417+ }
418+ Annotatable :: ImplItem ( item) => {
419+ Annotatable :: ImplItem ( item. map ( |item| cfg. fold_impl_item ( item) . pop ( ) . unwrap ( ) ) )
420+ }
421+ }
422+ }
423+
403424 fn expand_invoc ( & mut self , invoc : Invocation , ext : Rc < SyntaxExtension > ) -> Expansion {
404425 let result = match invoc. kind {
405426 InvocationKind :: Bang { .. } => self . expand_bang_invoc ( invoc, ext) ,
@@ -740,15 +761,6 @@ struct InvocationCollector<'a, 'b: 'a> {
740761 monotonic : bool ,
741762}
742763
743- macro_rules! fully_configure {
744- ( $this: ident, $node: ident, $noop_fold: ident) => {
745- match $noop_fold( $node, & mut $this. cfg) . pop( ) {
746- Some ( node) => node,
747- None => return SmallVector :: new( ) ,
748- }
749- }
750- }
751-
752764impl < ' a , ' b > InvocationCollector < ' a , ' b > {
753765 fn collect ( & mut self , expansion_kind : ExpansionKind , kind : InvocationKind ) -> Expansion {
754766 let mark = Mark :: fresh ( self . cx . current_expansion . mark ) ;
@@ -900,7 +912,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
900912
901913 let ( attr, traits, mut item) = self . classify_item ( item) ;
902914 if attr. is_some ( ) || !traits. is_empty ( ) {
903- let item = Annotatable :: Item ( fully_configure ! ( self , item, noop_fold_item ) ) ;
915+ let item = Annotatable :: Item ( item) ;
904916 return self . collect_attr ( attr, traits, item, ExpansionKind :: Items ) . make_items ( ) ;
905917 }
906918
@@ -974,8 +986,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
974986
975987 let ( attr, traits, item) = self . classify_item ( item) ;
976988 if attr. is_some ( ) || !traits. is_empty ( ) {
977- let item =
978- Annotatable :: TraitItem ( P ( fully_configure ! ( self , item, noop_fold_trait_item) ) ) ;
989+ let item = Annotatable :: TraitItem ( P ( item) ) ;
979990 return self . collect_attr ( attr, traits, item, ExpansionKind :: TraitItems )
980991 . make_trait_items ( )
981992 }
@@ -995,7 +1006,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
9951006
9961007 let ( attr, traits, item) = self . classify_item ( item) ;
9971008 if attr. is_some ( ) || !traits. is_empty ( ) {
998- let item = Annotatable :: ImplItem ( P ( fully_configure ! ( self , item, noop_fold_impl_item ) ) ) ;
1009+ let item = Annotatable :: ImplItem ( P ( item) ) ;
9991010 return self . collect_attr ( attr, traits, item, ExpansionKind :: ImplItems )
10001011 . make_impl_items ( ) ;
10011012 }
0 commit comments