Skip to content

Commit 50e48b0

Browse files
committed
---
yaml --- r: 153110 b: refs/heads/try2 c: b8cd7f7 h: refs/heads/master v: v3
1 parent 0a6c8b7 commit 50e48b0

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9fdaa948c03a33e703eb5830dbed82ee2afe5101
8+
refs/heads/try2: b8cd7f7c6df3581df92c2dc51ca23770f468de40
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)