@@ -251,7 +251,7 @@ fn expand_loop_block(loop_block: P<Block>,
251
251
// the same context will pick that up in the deferred renaming pass
252
252
// and be renamed incorrectly.
253
253
let mut rename_list = vec ! ( rename) ;
254
- let mut rename_fld = renames_to_fold ( & mut rename_list) ;
254
+ let mut rename_fld = IdentRenamer { renames : & mut rename_list} ;
255
255
let renamed_ident = rename_fld. fold_ident ( label) ;
256
256
257
257
// The rename *must* be added to the enclosed syntax context for
@@ -624,7 +624,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
624
624
}
625
625
let rewritten_pat = {
626
626
let mut rename_fld =
627
- renames_to_fold ( & mut new_pending_renames) ;
627
+ IdentRenamer { renames : & mut new_pending_renames} ;
628
628
// rewrite the pattern using the new names (the old
629
629
// ones have already been applied):
630
630
rename_fld. fold_pat ( expanded_pat)
@@ -676,8 +676,7 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
676
676
new_pending_renames. push ( ( * ident, new_name) ) ;
677
677
}
678
678
let rewritten_pat = {
679
- let mut rename_fld =
680
- renames_to_fold ( & mut new_pending_renames) ;
679
+ let mut rename_fld = IdentRenamer { renames : & mut new_pending_renames} ;
681
680
// rewrite the pattern using the new names (the old
682
681
// ones have already been applied):
683
682
rename_fld. fold_pat ( expanded_pat)
@@ -757,17 +756,19 @@ fn expand_block_elts(b: &Block, fld: &mut MacroExpander) -> P<Block> {
757
756
let new_view_items = b. view_items . iter ( ) . map ( |x| fld. fold_view_item ( x) ) . collect ( ) ;
758
757
let new_stmts =
759
758
b. stmts . iter ( ) . flat_map ( |x| {
759
+ // perform all pending renames
760
760
let renamed_stmt = {
761
761
let pending_renames = & mut fld. extsbox . info ( ) . pending_renames ;
762
- let mut rename_fld = renames_to_fold ( pending_renames) ;
762
+ let mut rename_fld = IdentRenamer { renames : pending_renames} ;
763
763
rename_fld. fold_stmt ( & * * x) . expect_one ( "rename_fold didn't return one value" )
764
764
} ;
765
+ // expand macros in the statement
765
766
fld. fold_stmt ( & * renamed_stmt) . move_iter ( )
766
767
} ) . collect ( ) ;
767
768
let new_expr = b. expr . map ( |x| {
768
769
let expr = {
769
770
let pending_renames = & mut fld. extsbox . info ( ) . pending_renames ;
770
- let mut rename_fld = renames_to_fold ( pending_renames) ;
771
+ let mut rename_fld = IdentRenamer { renames : pending_renames} ;
771
772
rename_fld. fold_expr ( x)
772
773
} ;
773
774
fld. fold_expr ( expr)
@@ -859,6 +860,7 @@ fn expand_pat(p: Gc<ast::Pat>, fld: &mut MacroExpander) -> Gc<ast::Pat> {
859
860
}
860
861
}
861
862
863
+ // a tree-folder that applies every rename in its (mutable) list
862
864
pub struct IdentRenamer < ' a > {
863
865
renames : & ' a mut RenameList ,
864
866
}
@@ -875,14 +877,6 @@ impl<'a> Folder for IdentRenamer<'a> {
875
877
}
876
878
}
877
879
878
- // given a mutable list of renames, return a tree-folder that applies those
879
- // renames.
880
- fn renames_to_fold < ' a > ( renames : & ' a mut RenameList ) -> IdentRenamer < ' a > {
881
- IdentRenamer {
882
- renames : renames,
883
- }
884
- }
885
-
886
880
fn new_span ( cx : & ExtCtxt , sp : Span ) -> Span {
887
881
/* this discards information in the case of macro-defining macros */
888
882
Span {
0 commit comments