From 6bee3c87c94a39fb7d48a119bbc105149c345bfc Mon Sep 17 00:00:00 2001 From: John Clements Date: Fri, 4 Jul 2014 12:15:24 -0700 Subject: [PATCH] use PatIdentRenamer for match bindings --- src/libsyntax/ext/expand.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 55bc5e3c3036..694e69c7a2cb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -667,19 +667,14 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm { // code duplicated from 'let', above. Perhaps this can be lifted // into a separate function: let idents = pattern_bindings(*first_pat); - let mut new_pending_renames = + let new_pending_renames = idents.iter().map(|id| (*id,fresh_name(id))).collect(); - // rewrite all of the patterns using the new names (the old - // ones have already been applied). Note that we depend here - // on the guarantee that after expansion, there can't be any - // Path expressions (a.k.a. varrefs) left in the pattern. If - // this were false, we'd need to apply this renaming only to - // the bindings, and not to the varrefs, using a more targeted - // fold-er. - let mut rename_fld = IdentRenamer{renames:&mut new_pending_renames}; + // apply the renaming, but only to the PatIdents: + let mut rename_pats_fld = PatIdentRenamer{renames:&new_pending_renames}; let rewritten_pats = - expanded_pats.iter().map(|pat| rename_fld.fold_pat(*pat)).collect(); + expanded_pats.iter().map(|pat| rename_pats_fld.fold_pat(*pat)).collect(); // apply renaming and then expansion to the guard and the body: + let mut rename_fld = IdentRenamer{renames:&new_pending_renames}; let rewritten_guard = arm.guard.map(|g| fld.fold_expr(rename_fld.fold_expr(g))); let rewritten_body = fld.fold_expr(rename_fld.fold_expr(arm.body));