]> git.lizzy.rs Git - rust.git/commitdiff
implement hygiene for method args
authorJohn Clements <clements@racket-lang.org>
Fri, 4 Jul 2014 18:24:28 +0000 (11:24 -0700)
committerJohn Clements <clements@racket-lang.org>
Tue, 8 Jul 2014 23:27:37 +0000 (16:27 -0700)
src/libsyntax/ext/expand.rs

index 47c86f1c9f5c2f487e962f5f5240ba25677129c3..f51002f734cd46eaddd48db6d6fa699f00820c46 100644 (file)
@@ -934,6 +934,27 @@ fn fold_pat(&mut self, pat: Gc<ast::Pat>) -> Gc<ast::Pat> {
     }
 }
 
+// expand a method
+fn expand_method(m: &ast::Method, fld: &mut MacroExpander) -> Gc<ast::Method> {
+    let id = fld.new_id(m.id);
+    let (rewritten_fn_decl, rewritten_body)
+        = expand_and_rename_fn_decl_and_block(m.decl,m.body,fld);
+
+    // all of the other standard stuff:
+    box(GC) ast::Method {
+        id: id,
+        ident: fld.fold_ident(m.ident),
+        attrs: m.attrs.iter().map(|a| fld.fold_attribute(*a)).collect(),
+        generics: fold_generics(&m.generics, fld),
+        explicit_self: fld.fold_explicit_self(&m.explicit_self),
+        fn_style: m.fn_style,
+        decl: rewritten_fn_decl,
+        body: rewritten_body,
+        span: fld.new_span(m.span),
+        vis: m.vis
+    }
+}
+
 /// Given a fn_decl and a block and a MacroExpander, expand the fn_decl, then use the
 /// PatIdents in its arguments to perform renaming in the FnDecl and
 /// the block, returning both the new FnDecl and the new Block.
@@ -988,6 +1009,10 @@ fn fold_arm(&mut self, arm: &ast::Arm) -> ast::Arm {
         expand_arm(arm, self)
     }
 
+    fn fold_method(&mut self, method: Gc<ast::Method>) -> Gc<ast::Method> {
+        expand_method(method, self)
+    }
+
     fn new_span(&mut self, span: Span) -> Span {
         new_span(self.cx, span)
     }