Skip to content

Commit 33f28d8

Browse files
committed
---
yaml --- r: 122832 b: refs/heads/master c: b8cd7f7 h: refs/heads/master v: v3
1 parent c2173c3 commit 33f28d8

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9fdaa948c03a33e703eb5830dbed82ee2afe5101
2+
refs/heads/master: b8cd7f7c6df3581df92c2dc51ca23770f468de40
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: aaff4e05e19b48d81e4ecb3337f288f42d06edd0
55
refs/heads/try: 2e9d9477b848cec778ca3f07ecdf0aea6ade23de

trunk/src/libsyntax/ext/expand.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use codemap;
2121
use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
2222
use crateid::CrateId;
2323
use ext::base::*;
24+
use fold;
2425
use fold::*;
2526
use parse;
2627
use parse::token::{fresh_mark, fresh_name, intern};
@@ -856,15 +857,36 @@ impl<'a> Folder for IdentRenamer<'a> {
856857
}
857858
}
858859

859-
fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
860-
/* this discards information in the case of macro-defining macros */
861-
Span {
862-
lo: sp.lo,
863-
hi: sp.hi,
864-
expn_info: cx.backtrace(),
860+
/// A tree-folder that applies every rename in its list to
861+
/// the idents that are in PatIdent patterns. This is more narrowly
862+
/// focused than IdentRenamer, and is needed for FnDecl,
863+
/// where we want to rename the args but not the fn name or the generics etc.
864+
pub struct PatIdentRenamer<'a> {
865+
renames: &'a mtwt::RenameList,
866+
}
867+
868+
impl<'a> Folder for PatIdentRenamer<'a> {
869+
fn fold_pat(&mut self, pat: Gc<ast::Pat>) -> Gc<ast::Pat> {
870+
match pat.node {
871+
ast::PatIdent(binding_mode, Spanned{span: ref sp, node: id}, ref sub) => {
872+
let new_ident = Ident{name: id.name,
873+
ctxt: mtwt::new_renames(self.renames, id.ctxt)};
874+
let new_node =
875+
ast::PatIdent(binding_mode,
876+
Spanned{span: self.new_span(*sp), node: new_ident},
877+
sub.map(|p| self.fold_pat(p)));
878+
box(GC) ast::Pat {
879+
id: pat.id,
880+
span: self.new_span(pat.span),
881+
node: new_node,
882+
}
883+
},
884+
_ => noop_fold_pat(pat, self)
885+
}
865886
}
866887
}
867888

889+
/// A tree-folder that performs macro expansion
868890
pub struct MacroExpander<'a, 'b> {
869891
pub extsbox: SyntaxEnv,
870892
pub cx: &'a mut ExtCtxt<'b>,
@@ -900,6 +922,15 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
900922
}
901923
}
902924

925+
fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
926+
/* this discards information in the case of macro-defining macros */
927+
Span {
928+
lo: sp.lo,
929+
hi: sp.hi,
930+
expn_info: cx.backtrace(),
931+
}
932+
}
933+
903934
pub struct ExpansionConfig {
904935
pub deriving_hash_type_parameter: bool,
905936
pub crate_id: CrateId,

0 commit comments

Comments
 (0)