@@ -21,6 +21,7 @@ use codemap;
21
21
use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
22
22
use crateid:: CrateId ;
23
23
use ext:: base:: * ;
24
+ use fold;
24
25
use fold:: * ;
25
26
use parse;
26
27
use parse:: token:: { fresh_mark, fresh_name, intern} ;
@@ -856,15 +857,36 @@ impl<'a> Folder for IdentRenamer<'a> {
856
857
}
857
858
}
858
859
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
+ }
865
886
}
866
887
}
867
888
889
+ /// A tree-folder that performs macro expansion
868
890
pub struct MacroExpander < ' a , ' b > {
869
891
pub extsbox : SyntaxEnv ,
870
892
pub cx : & ' a mut ExtCtxt < ' b > ,
@@ -900,6 +922,15 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
900
922
}
901
923
}
902
924
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
+
903
934
pub struct ExpansionConfig {
904
935
pub deriving_hash_type_parameter : bool ,
905
936
pub crate_id : CrateId ,
0 commit comments