Skip to content

Commit 84e8143

Browse files
committed
get rid of needless wrapper function
1 parent c956f76 commit 84e8143

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn expand_loop_block(loop_block: P<Block>,
251251
// the same context will pick that up in the deferred renaming pass
252252
// and be renamed incorrectly.
253253
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};
255255
let renamed_ident = rename_fld.fold_ident(label);
256256

257257
// 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)
624624
}
625625
let rewritten_pat = {
626626
let mut rename_fld =
627-
renames_to_fold(&mut new_pending_renames);
627+
IdentRenamer{renames: &mut new_pending_renames};
628628
// rewrite the pattern using the new names (the old
629629
// ones have already been applied):
630630
rename_fld.fold_pat(expanded_pat)
@@ -676,8 +676,7 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
676676
new_pending_renames.push((*ident,new_name));
677677
}
678678
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};
681680
// rewrite the pattern using the new names (the old
682681
// ones have already been applied):
683682
rename_fld.fold_pat(expanded_pat)
@@ -757,17 +756,19 @@ fn expand_block_elts(b: &Block, fld: &mut MacroExpander) -> P<Block> {
757756
let new_view_items = b.view_items.iter().map(|x| fld.fold_view_item(x)).collect();
758757
let new_stmts =
759758
b.stmts.iter().flat_map(|x| {
759+
// perform all pending renames
760760
let renamed_stmt = {
761761
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};
763763
rename_fld.fold_stmt(&**x).expect_one("rename_fold didn't return one value")
764764
};
765+
// expand macros in the statement
765766
fld.fold_stmt(&*renamed_stmt).move_iter()
766767
}).collect();
767768
let new_expr = b.expr.map(|x| {
768769
let expr = {
769770
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};
771772
rename_fld.fold_expr(x)
772773
};
773774
fld.fold_expr(expr)
@@ -859,6 +860,7 @@ fn expand_pat(p: Gc<ast::Pat>, fld: &mut MacroExpander) -> Gc<ast::Pat> {
859860
}
860861
}
861862

863+
// a tree-folder that applies every rename in its (mutable) list
862864
pub struct IdentRenamer<'a> {
863865
renames: &'a mut RenameList,
864866
}
@@ -875,14 +877,6 @@ impl<'a> Folder for IdentRenamer<'a> {
875877
}
876878
}
877879

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-
886880
fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
887881
/* this discards information in the case of macro-defining macros */
888882
Span {

0 commit comments

Comments
 (0)