@@ -465,18 +465,28 @@ fn expand_item(item: P<ast::Item>, fld: &mut MacroExpander) -> SmallVector<P<ast
465
465
_ => unreachable ! ( ) ,
466
466
} )
467
467
}
468
- ast:: ItemKind :: Mod ( _ ) | ast:: ItemKind :: ForeignMod ( _ ) => {
469
- let valid_ident =
470
- item. ident . name != keywords :: Invalid . name ( ) ;
468
+ ast:: ItemKind :: Mod ( ast:: Mod { inner , .. } ) => {
469
+ fld . cx . mod_push ( item . ident ) ;
470
+ let macro_use = contains_macro_use ( fld , & item. attrs ) ;
471
471
472
- if valid_ident {
473
- fld. cx . mod_push ( item. ident ) ;
472
+ let directory = fld. cx . directory . clone ( ) ;
473
+ if item. span . contains ( inner) {
474
+ fld. cx . directory . push ( & * {
475
+ :: attr:: first_attr_value_str_by_name ( & item. attrs , "path" )
476
+ . unwrap_or ( item. ident . name . as_str ( ) )
477
+ } ) ;
478
+ } else {
479
+ fld. cx . directory = match inner {
480
+ syntax_pos:: DUMMY_SP => PathBuf :: new ( ) ,
481
+ _ => PathBuf :: from ( fld. cx . parse_sess . codemap ( ) . span_to_filename ( inner) ) ,
482
+ } ;
483
+ fld. cx . directory . pop ( ) ;
474
484
}
475
- let macro_use = contains_macro_use ( fld , & item . attrs ) ;
485
+
476
486
let result = fld. with_exts_frame ( macro_use, |fld| noop_fold_item ( item, fld) ) ;
477
- if valid_ident {
478
- fld . cx . mod_pop ( ) ;
479
- }
487
+ fld . cx . directory = directory ;
488
+
489
+ fld . cx . mod_pop ( ) ;
480
490
result
481
491
} ,
482
492
_ => noop_fold_item ( item, fld) ,
@@ -639,31 +649,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
639
649
}
640
650
641
651
fn fold_item ( & mut self , item : P < ast:: Item > ) -> SmallVector < P < ast:: Item > > {
642
- use std:: mem:: replace;
643
- let result;
644
- if let ast:: ItemKind :: Mod ( ast:: Mod { inner, .. } ) = item. node {
645
- if item. span . contains ( inner) {
646
- let directory = self . cx . directory . clone ( ) ;
647
- self . cx . directory . push ( & * {
648
- :: attr:: first_attr_value_str_by_name ( & item. attrs , "path" )
649
- . unwrap_or ( item. ident . name . as_str ( ) )
650
- } ) ;
651
- result = expand_annotatable ( Annotatable :: Item ( item) , self ) . make_items ( ) ;
652
- self . cx . directory = directory;
653
- } else {
654
- let mut directory = match inner {
655
- syntax_pos:: DUMMY_SP => PathBuf :: new ( ) ,
656
- _ => PathBuf :: from ( self . cx . parse_sess . codemap ( ) . span_to_filename ( inner) ) ,
657
- } ;
658
- directory. pop ( ) ;
659
- let directory = replace ( & mut self . cx . directory , directory) ;
660
- result = expand_annotatable ( Annotatable :: Item ( item) , self ) . make_items ( ) ;
661
- self . cx . directory = directory;
662
- }
663
- } else {
664
- result = expand_annotatable ( Annotatable :: Item ( item) , self ) . make_items ( ) ;
665
- }
666
- result
652
+ expand_annotatable ( Annotatable :: Item ( item) , self ) . make_items ( )
667
653
}
668
654
669
655
fn fold_stmt ( & mut self , stmt : ast:: Stmt ) -> SmallVector < ast:: Stmt > {
0 commit comments