about summary refs log tree commit diff
path: root/src/librustc/front
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-10-27 14:25:57 +0000
committerbors <bors@rust-lang.org>2015-10-27 14:25:57 +0000
commit679b5a9faaed845bf4a4bd8fe27a2a98df78b7ad (patch)
tree27eb4af7bc55419ba66729cc3fbeeb0b6be7b666 /src/librustc/front
parenteab5ad529bf1d0406b25c52cc1b5281bc54c5679 (diff)
parent4e2189fe457e246654f6da6152da1609b392aeea (diff)
Auto merge of #29327 - sanxiyn:argument, r=nrc
Fix #24114.
Diffstat (limited to 'src/librustc/front')
-rw-r--r--src/librustc/front/map/collector.rs17
-rw-r--r--src/librustc/front/map/mod.rs32
2 files changed, 22 insertions, 27 deletions
diff --git a/src/librustc/front/map/collector.rs b/src/librustc/front/map/collector.rs
index 458e423b826..f255949a9f5 100644
--- a/src/librustc/front/map/collector.rs
+++ b/src/librustc/front/map/collector.rs
@@ -104,12 +104,6 @@ impl<'ast> NodeCollector<'ast> {
         let entry = MapEntry::from_node(self.parent_node, node);
         self.insert_entry(id, entry);
     }
-
-    fn visit_fn_decl(&mut self, decl: &'ast FnDecl) {
-        for a in &decl.inputs {
-            self.insert(a.id, NodeArg(&*a.pat));
-        }
-    }
 }
 
 impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
@@ -295,20 +289,9 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
     fn visit_fn(&mut self, fk: visit::FnKind<'ast>, fd: &'ast FnDecl,
                 b: &'ast Block, s: Span, id: NodeId) {
         assert_eq!(self.parent_node, id);
-        self.visit_fn_decl(fd);
         visit::walk_fn(self, fk, fd, b, s);
     }
 
-    fn visit_ty(&mut self, ty: &'ast Ty) {
-        match ty.node {
-            TyBareFn(ref fd) => {
-                self.visit_fn_decl(&*fd.decl);
-            }
-            _ => {}
-        }
-        visit::walk_ty(self, ty);
-    }
-
     fn visit_block(&mut self, block: &'ast Block) {
         self.insert(block.id, NodeBlock(block));
         let parent_node = self.parent_node;
diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs
index 2d84f6fc2be..94800db184e 100644
--- a/src/librustc/front/map/mod.rs
+++ b/src/librustc/front/map/mod.rs
@@ -118,7 +118,6 @@ pub enum Node<'ast> {
     NodeVariant(&'ast Variant),
     NodeExpr(&'ast Expr),
     NodeStmt(&'ast Stmt),
-    NodeArg(&'ast Pat),
     NodeLocal(&'ast Pat),
     NodePat(&'ast Pat),
     NodeBlock(&'ast Block),
@@ -145,7 +144,6 @@ pub enum MapEntry<'ast> {
     EntryVariant(NodeId, &'ast Variant),
     EntryExpr(NodeId, &'ast Expr),
     EntryStmt(NodeId, &'ast Stmt),
-    EntryArg(NodeId, &'ast Pat),
     EntryLocal(NodeId, &'ast Pat),
     EntryPat(NodeId, &'ast Pat),
     EntryBlock(NodeId, &'ast Block),
@@ -180,7 +178,6 @@ impl<'ast> MapEntry<'ast> {
             NodeVariant(n) => EntryVariant(p, n),
             NodeExpr(n) => EntryExpr(p, n),
             NodeStmt(n) => EntryStmt(p, n),
-            NodeArg(n) => EntryArg(p, n),
             NodeLocal(n) => EntryLocal(p, n),
             NodePat(n) => EntryPat(p, n),
             NodeBlock(n) => EntryBlock(p, n),
@@ -199,7 +196,6 @@ impl<'ast> MapEntry<'ast> {
             EntryVariant(id, _) => id,
             EntryExpr(id, _) => id,
             EntryStmt(id, _) => id,
-            EntryArg(id, _) => id,
             EntryLocal(id, _) => id,
             EntryPat(id, _) => id,
             EntryBlock(id, _) => id,
@@ -219,7 +215,6 @@ impl<'ast> MapEntry<'ast> {
             EntryVariant(_, n) => NodeVariant(n),
             EntryExpr(_, n) => NodeExpr(n),
             EntryStmt(_, n) => NodeStmt(n),
-            EntryArg(_, n) => NodeArg(n),
             EntryLocal(_, n) => NodeLocal(n),
             EntryPat(_, n) => NodePat(n),
             EntryBlock(_, n) => NodeBlock(n),
@@ -348,6 +343,27 @@ impl<'ast> Map<'ast> {
         self.find_entry(id).and_then(|x| x.parent_node()).unwrap_or(id)
     }
 
+    /// Check if the node is an argument. An argument is a local variable whose
+    /// immediate parent is an item or a closure.
+    pub fn is_argument(&self, id: NodeId) -> bool {
+        match self.find(id) {
+            Some(NodeLocal(_)) => (),
+            _ => return false,
+        }
+        match self.find(self.get_parent_node(id)) {
+            Some(NodeItem(_)) |
+            Some(NodeTraitItem(_)) |
+            Some(NodeImplItem(_)) => true,
+            Some(NodeExpr(e)) => {
+                match e.node {
+                    ExprClosure(..) => true,
+                    _ => false,
+                }
+            }
+            _ => false,
+        }
+    }
+
     /// If there is some error when walking the parents (e.g., a node does not
     /// have a parent in the map or a node can't be found), then we return the
     /// last good node id we found. Note that reaching the crate root (id == 0),
@@ -628,7 +644,7 @@ impl<'ast> Map<'ast> {
             Some(NodeVariant(variant)) => variant.span,
             Some(NodeExpr(expr)) => expr.span,
             Some(NodeStmt(stmt)) => stmt.span,
-            Some(NodeArg(pat)) | Some(NodeLocal(pat)) => pat.span,
+            Some(NodeLocal(pat)) => pat.span,
             Some(NodePat(pat)) => pat.span,
             Some(NodeBlock(block)) => block.span,
             Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span,
@@ -886,7 +902,6 @@ impl<'a> NodePrinter for pprust::State<'a> {
             // ast_map to reconstruct their full structure for pretty
             // printing.
             NodeLocal(_)       => panic!("cannot print isolated Local"),
-            NodeArg(_)         => panic!("cannot print isolated Arg"),
             NodeStructCtor(_)  => panic!("cannot print isolated StructCtor"),
         }
     }
@@ -965,9 +980,6 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
         Some(NodeStmt(ref stmt)) => {
             format!("stmt {}{}", pprust::stmt_to_string(&**stmt), id_str)
         }
-        Some(NodeArg(ref pat)) => {
-            format!("arg {}{}", pprust::pat_to_string(&**pat), id_str)
-        }
         Some(NodeLocal(ref pat)) => {
             format!("local {}{}", pprust::pat_to_string(&**pat), id_str)
         }