about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-04-14 09:54:58 +1200
committerNick Cameron <ncameron@mozilla.com>2015-04-14 09:54:58 +1200
commit01678acf5066e2c4d29f3617ac5892acedf3ddbe (patch)
tree5d72021be517bd2461880462f0a9c87b4f2a9a29 /src/libsyntax
parentf55e66aaed42589dcda0221a4545dbaaec68e577 (diff)
downloadrust-01678acf5066e2c4d29f3617ac5892acedf3ddbe.tar.gz
rust-01678acf5066e2c4d29f3617ac5892acedf3ddbe.zip
Expose visibility for fns in syntax::visit
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_map/blocks.rs29
-rw-r--r--src/libsyntax/ast_util.rs4
-rw-r--r--src/libsyntax/feature_gate.rs6
-rw-r--r--src/libsyntax/visit.rs14
4 files changed, 30 insertions, 23 deletions
diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs
index 475970ac30a..1505d1e91b8 100644
--- a/src/libsyntax/ast_map/blocks.rs
+++ b/src/libsyntax/ast_map/blocks.rs
@@ -121,6 +121,7 @@ struct ItemFnParts<'a> {
     decl:     &'a ast::FnDecl,
     unsafety: ast::Unsafety,
     abi:      abi::Abi,
+    vis:      ast::Visibility,
     generics: &'a ast::Generics,
     body:     &'a Block,
     id:       ast::NodeId,
@@ -155,44 +156,50 @@ impl<'a> FnLikeNode<'a> {
 
     pub fn body(self) -> &'a Block {
         self.handle(|i: ItemFnParts<'a>|  &*i.body,
-                    |_, _, _: &'a ast::MethodSig, body: &'a ast::Block, _|  body,
+                    |_, _, _: &'a ast::MethodSig, _, body: &'a ast::Block, _|  body,
                     |c: ClosureParts<'a>| c.body)
     }
 
     pub fn decl(self) -> &'a FnDecl {
         self.handle(|i: ItemFnParts<'a>|  &*i.decl,
-                    |_, _, sig: &'a ast::MethodSig, _, _|  &sig.decl,
+                    |_, _, sig: &'a ast::MethodSig, _, _, _|  &sig.decl,
                     |c: ClosureParts<'a>| c.decl)
     }
 
     pub fn span(self) -> Span {
         self.handle(|i: ItemFnParts|     i.span,
-                    |_, _, _: &'a ast::MethodSig, _, span| span,
+                    |_, _, _: &'a ast::MethodSig, _, _, span| span,
                     |c: ClosureParts|    c.span)
     }
 
     pub fn id(self) -> NodeId {
         self.handle(|i: ItemFnParts|     i.id,
-                    |id, _, _: &'a ast::MethodSig, _, _| id,
+                    |id, _, _: &'a ast::MethodSig, _, _, _| id,
                     |c: ClosureParts|    c.id)
     }
 
     pub fn kind(self) -> visit::FnKind<'a> {
         let item = |p: ItemFnParts<'a>| -> visit::FnKind<'a> {
-            visit::FkItemFn(p.ident, p.generics, p.unsafety, p.abi)
+            visit::FkItemFn(p.ident, p.generics, p.unsafety, p.abi, p.vis)
         };
         let closure = |_: ClosureParts| {
             visit::FkFnBlock
         };
-        let method = |_, ident, sig: &'a ast::MethodSig, _, _| {
-            visit::FkMethod(ident, sig)
+        let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| {
+            visit::FkMethod(ident, sig, vis)
         };
         self.handle(item, method, closure)
     }
 
     fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
         I: FnOnce(ItemFnParts<'a>) -> A,
-        M: FnOnce(NodeId, ast::Ident, &'a ast::MethodSig, &'a ast::Block, Span) -> A,
+        M: FnOnce(NodeId,
+                  ast::Ident,
+                  &'a ast::MethodSig,
+                  Option<ast::Visibility>,
+                  &'a ast::Block,
+                  Span)
+                  -> A,
         C: FnOnce(ClosureParts<'a>) -> A,
     {
         match self.node {
@@ -200,20 +207,20 @@ impl<'a> FnLikeNode<'a> {
                 ast::ItemFn(ref decl, unsafety, abi, ref generics, ref block) =>
                     item_fn(ItemFnParts{
                         ident: i.ident, decl: &**decl, unsafety: unsafety, body: &**block,
-                        generics: generics, abi: abi, id: i.id, span: i.span
+                        generics: generics, abi: abi, vis: i.vis, id: i.id, span: i.span
                     }),
                 _ => panic!("item FnLikeNode that is not fn-like"),
             },
             ast_map::NodeTraitItem(ti) => match ti.node {
                 ast::MethodTraitItem(ref sig, Some(ref body)) => {
-                    method(ti.id, ti.ident, sig, body, ti.span)
+                    method(ti.id, ti.ident, sig, None, body, ti.span)
                 }
                 _ => panic!("trait method FnLikeNode that is not fn-like"),
             },
             ast_map::NodeImplItem(ii) => {
                 match ii.node {
                     ast::MethodImplItem(ref sig, ref body) => {
-                        method(ii.id, ii.ident, sig, body, ii.span)
+                        method(ii.id, ii.ident, sig, Some(ii.vis), body, ii.span)
                     }
                     ast::TypeImplItem(_) |
                     ast::MacImplItem(_) => {
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index c4c2249d029..0ad75c5ec8c 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -440,10 +440,10 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
         self.operation.visit_id(node_id);
 
         match function_kind {
-            visit::FkItemFn(_, generics, _, _) => {
+            visit::FkItemFn(_, generics, _, _, _) => {
                 self.visit_generics_helper(generics)
             }
-            visit::FkMethod(_, sig) => {
+            visit::FkMethod(_, sig, _) => {
                 self.visit_generics_helper(&sig.generics)
             }
             visit::FkFnBlock => {}
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 689b4595d39..a6f8a718b33 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -644,13 +644,13 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
                 span: Span,
                 _node_id: NodeId) {
         match fn_kind {
-            visit::FkItemFn(_, _, _, abi) if abi == Abi::RustIntrinsic => {
+            visit::FkItemFn(_, _, _, abi, _) if abi == Abi::RustIntrinsic => {
                 self.gate_feature("intrinsics",
                                   span,
                                   "intrinsics are subject to change")
             }
-            visit::FkItemFn(_, _, _, abi) |
-            visit::FkMethod(_, &ast::MethodSig { abi, .. }) if abi == Abi::RustCall => {
+            visit::FkItemFn(_, _, _, abi, _) |
+            visit::FkMethod(_, &ast::MethodSig { abi, .. }, _) if abi == Abi::RustCall => {
                 self.gate_feature("unboxed_closures",
                                   span,
                                   "rust-call ABI is subject to change")
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 5c345c75642..4c70fc9f81f 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -35,10 +35,10 @@ use owned_slice::OwnedSlice;
 #[derive(Copy, Clone)]
 pub enum FnKind<'a> {
     /// fn foo() or extern "Abi" fn foo()
-    FkItemFn(Ident, &'a Generics, Unsafety, Abi),
+    FkItemFn(Ident, &'a Generics, Unsafety, Abi, Visibility),
 
     /// fn foo(&self)
-    FkMethod(Ident, &'a MethodSig),
+    FkMethod(Ident, &'a MethodSig, Option<Visibility>),
 
     /// |x, y| ...
     /// proc(x, y) ...
@@ -247,7 +247,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
             visitor.visit_expr(&**expr);
         }
         ItemFn(ref declaration, fn_style, abi, ref generics, ref body) => {
-            visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi),
+            visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi, item.vis),
                              &**declaration,
                              &**body,
                              item.span,
@@ -600,10 +600,10 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
     walk_fn_decl(visitor, function_declaration);
 
     match function_kind {
-        FkItemFn(_, generics, _, _) => {
+        FkItemFn(_, generics, _, _, _) => {
             visitor.visit_generics(generics);
         }
-        FkMethod(_, sig) => {
+        FkMethod(_, sig, _) => {
             visitor.visit_generics(&sig.generics);
             visitor.visit_explicit_self(&sig.explicit_self);
         }
@@ -625,7 +625,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
             walk_fn_decl(visitor, &sig.decl);
         }
         MethodTraitItem(ref sig, Some(ref body)) => {
-            visitor.visit_fn(FkMethod(trait_item.ident, sig), &sig.decl,
+            visitor.visit_fn(FkMethod(trait_item.ident, sig, None), &sig.decl,
                              body, trait_item.span, trait_item.id);
         }
         TypeTraitItem(ref bounds, ref default) => {
@@ -642,7 +642,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
     }
     match impl_item.node {
         MethodImplItem(ref sig, ref body) => {
-            visitor.visit_fn(FkMethod(impl_item.ident, sig), &sig.decl,
+            visitor.visit_fn(FkMethod(impl_item.ident, sig, Some(impl_item.vis)), &sig.decl,
                              body, impl_item.span, impl_item.id);
         }
         TypeImplItem(ref ty) => {