about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/hir/map/collector.rs9
-rw-r--r--src/librustc/hir/map/mod.rs35
-rw-r--r--src/librustc/middle/mem_categorization.rs2
-rw-r--r--src/librustc/ty/mod.rs2
-rw-r--r--src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs14
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs2
-rw-r--r--src/librustc_mir/build/mod.rs2
-rw-r--r--src/librustc_save_analysis/lib.rs2
-rw-r--r--src/test/run-pass/issue-43910.rs16
9 files changed, 53 insertions, 31 deletions
diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs
index d3ae3e0e8e8..0928081decd 100644
--- a/src/librustc/hir/map/collector.rs
+++ b/src/librustc/hir/map/collector.rs
@@ -138,7 +138,7 @@ impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
 
     fn visit_pat(&mut self, pat: &'hir Pat) {
         let node = if let PatKind::Binding(..) = pat.node {
-            NodeLocal(pat)
+            NodeBinding(pat)
         } else {
             NodePat(pat)
         };
@@ -195,6 +195,13 @@ impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
         });
     }
 
+    fn visit_local(&mut self, l: &'hir Local) {
+        self.insert(l.id, NodeLocal(l));
+        self.with_parent(l.id, |this| {
+            intravisit::walk_local(this, l)
+        })
+    }
+
     fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
         self.insert(lifetime.id, NodeLifetime(lifetime));
     }
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index 8cd229a2adf..1ff3166110a 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -53,9 +53,10 @@ pub enum Node<'hir> {
     NodeStmt(&'hir Stmt),
     NodeTy(&'hir Ty),
     NodeTraitRef(&'hir TraitRef),
-    NodeLocal(&'hir Pat),
+    NodeBinding(&'hir Pat),
     NodePat(&'hir Pat),
     NodeBlock(&'hir Block),
+    NodeLocal(&'hir Local),
 
     /// NodeStructCtor represents a tuple struct.
     NodeStructCtor(&'hir VariantData),
@@ -83,13 +84,14 @@ enum MapEntry<'hir> {
     EntryStmt(NodeId, &'hir Stmt),
     EntryTy(NodeId, &'hir Ty),
     EntryTraitRef(NodeId, &'hir TraitRef),
-    EntryLocal(NodeId, &'hir Pat),
+    EntryBinding(NodeId, &'hir Pat),
     EntryPat(NodeId, &'hir Pat),
     EntryBlock(NodeId, &'hir Block),
     EntryStructCtor(NodeId, &'hir VariantData),
     EntryLifetime(NodeId, &'hir Lifetime),
     EntryTyParam(NodeId, &'hir TyParam),
     EntryVisibility(NodeId, &'hir Visibility),
+    EntryLocal(NodeId, &'hir Local),
 
     /// Roots for node trees.
     RootCrate,
@@ -114,13 +116,14 @@ impl<'hir> MapEntry<'hir> {
             NodeStmt(n) => EntryStmt(p, n),
             NodeTy(n) => EntryTy(p, n),
             NodeTraitRef(n) => EntryTraitRef(p, n),
-            NodeLocal(n) => EntryLocal(p, n),
+            NodeBinding(n) => EntryBinding(p, n),
             NodePat(n) => EntryPat(p, n),
             NodeBlock(n) => EntryBlock(p, n),
             NodeStructCtor(n) => EntryStructCtor(p, n),
             NodeLifetime(n) => EntryLifetime(p, n),
             NodeTyParam(n) => EntryTyParam(p, n),
             NodeVisibility(n) => EntryVisibility(p, n),
+            NodeLocal(n) => EntryLocal(p, n),
         }
     }
 
@@ -136,13 +139,14 @@ impl<'hir> MapEntry<'hir> {
             EntryStmt(id, _) => id,
             EntryTy(id, _) => id,
             EntryTraitRef(id, _) => id,
-            EntryLocal(id, _) => id,
+            EntryBinding(id, _) => id,
             EntryPat(id, _) => id,
             EntryBlock(id, _) => id,
             EntryStructCtor(id, _) => id,
             EntryLifetime(id, _) => id,
             EntryTyParam(id, _) => id,
             EntryVisibility(id, _) => id,
+            EntryLocal(id, _) => id,
 
             NotPresent |
             RootCrate => return None,
@@ -161,13 +165,14 @@ impl<'hir> MapEntry<'hir> {
             EntryStmt(_, n) => NodeStmt(n),
             EntryTy(_, n) => NodeTy(n),
             EntryTraitRef(_, n) => NodeTraitRef(n),
-            EntryLocal(_, n) => NodeLocal(n),
+            EntryBinding(_, n) => NodeBinding(n),
             EntryPat(_, n) => NodePat(n),
             EntryBlock(_, n) => NodeBlock(n),
             EntryStructCtor(_, n) => NodeStructCtor(n),
             EntryLifetime(_, n) => NodeLifetime(n),
             EntryTyParam(_, n) => NodeTyParam(n),
             EntryVisibility(_, n) => NodeVisibility(n),
+            EntryLocal(_, n) => NodeLocal(n),
             _ => return None
         })
     }
@@ -319,13 +324,14 @@ impl<'hir> Map<'hir> {
                 EntryStmt(p, _) |
                 EntryTy(p, _) |
                 EntryTraitRef(p, _) |
-                EntryLocal(p, _) |
+                EntryBinding(p, _) |
                 EntryPat(p, _) |
                 EntryBlock(p, _) |
                 EntryStructCtor(p, _) |
                 EntryLifetime(p, _) |
                 EntryTyParam(p, _) |
-                EntryVisibility(p, _) =>
+                EntryVisibility(p, _) |
+                EntryLocal(p, _) =>
                     id = p,
 
                 EntryExpr(p, _) => {
@@ -589,7 +595,7 @@ impl<'hir> Map<'hir> {
     /// immediate parent is an item or a closure.
     pub fn is_argument(&self, id: NodeId) -> bool {
         match self.find(id) {
-            Some(NodeLocal(_)) => (),
+            Some(NodeBinding(_)) => (),
             _ => return false,
         }
         match self.find(self.get_parent_node(id)) {
@@ -856,7 +862,7 @@ impl<'hir> Map<'hir> {
             NodeField(f) => f.name,
             NodeLifetime(lt) => lt.name,
             NodeTyParam(tp) => tp.name,
-            NodeLocal(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
+            NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
             NodeStructCtor(_) => self.name(self.get_parent(id)),
             _ => bug!("no name for {}", self.node_to_string(id))
         }
@@ -915,7 +921,7 @@ impl<'hir> Map<'hir> {
             Some(EntryStmt(_, stmt)) => stmt.span,
             Some(EntryTy(_, ty)) => ty.span,
             Some(EntryTraitRef(_, tr)) => tr.path.span,
-            Some(EntryLocal(_, pat)) => pat.span,
+            Some(EntryBinding(_, pat)) => pat.span,
             Some(EntryPat(_, pat)) => pat.span,
             Some(EntryBlock(_, block)) => block.span,
             Some(EntryStructCtor(_, _)) => self.expect_item(self.get_parent(id)).span,
@@ -923,6 +929,7 @@ impl<'hir> Map<'hir> {
             Some(EntryTyParam(_, ty_param)) => ty_param.span,
             Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span,
             Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v),
+            Some(EntryLocal(_, local)) => local.span,
 
             Some(RootCrate) => self.forest.krate.span,
             Some(NotPresent) | None => {
@@ -1112,7 +1119,7 @@ impl<'a> print::State<'a> {
             NodeStmt(a)        => self.print_stmt(&a),
             NodeTy(a)          => self.print_type(&a),
             NodeTraitRef(a)    => self.print_trait_ref(&a),
-            NodeLocal(a)       |
+            NodeBinding(a)       |
             NodePat(a)         => self.print_pat(&a),
             NodeBlock(a)       => {
                 use syntax::print::pprust::PrintState;
@@ -1131,6 +1138,7 @@ impl<'a> print::State<'a> {
             // hir_map to reconstruct their full structure for pretty
             // printing.
             NodeStructCtor(_)  => bug!("cannot print isolated StructCtor"),
+            NodeLocal(a)       => self.print_local_decl(&a),
         }
     }
 }
@@ -1223,7 +1231,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
         Some(NodeTraitRef(_)) => {
             format!("trait_ref {}{}", map.node_to_pretty_string(id), id_str)
         }
-        Some(NodeLocal(_)) => {
+        Some(NodeBinding(_)) => {
             format!("local {}{}", map.node_to_pretty_string(id), id_str)
         }
         Some(NodePat(_)) => {
@@ -1232,6 +1240,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
         Some(NodeBlock(_)) => {
             format!("block {}{}", map.node_to_pretty_string(id), id_str)
         }
+        Some(NodeLocal(_)) => {
+            format!("local {}{}", map.node_to_pretty_string(id), id_str)
+        }
         Some(NodeStructCtor(_)) => {
             format!("struct_ctor {}{}", path_str(), id_str)
         }
diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs
index c8a7f8c4aaf..8cd023b8e63 100644
--- a/src/librustc/middle/mem_categorization.rs
+++ b/src/librustc/middle/mem_categorization.rs
@@ -332,7 +332,7 @@ impl MutabilityCategory {
 
     fn from_local(tcx: TyCtxt, tables: &ty::TypeckTables, id: ast::NodeId) -> MutabilityCategory {
         let ret = match tcx.hir.get(id) {
-            hir_map::NodeLocal(p) => match p.node {
+            hir_map::NodeBinding(p) => match p.node {
                 PatKind::Binding(..) => {
                     let bm = *tables.pat_binding_modes()
                                     .get(p.hir_id)
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 1daabd744ae..7e402075fcf 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -1971,7 +1971,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
 
     pub fn local_var_name_str(self, id: NodeId) -> InternedString {
         match self.hir.find(id) {
-            Some(hir_map::NodeLocal(pat)) => {
+            Some(hir_map::NodeBinding(pat)) => {
                 match pat.node {
                     hir::PatKind::Binding(_, _, ref path1, _) => path1.node.as_str(),
                     _ => {
diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
index 24c85429dab..78787627889 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
@@ -68,19 +68,7 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte
                     });
             PatternSource::MatchExpr(e)
         }
-        NodeStmt(ref s) => {
-            // the enclosing statement must be a `let` or something else
-            match s.node {
-                StmtDecl(ref decl, _) => {
-                    match decl.node {
-                        DeclLocal(ref local) => PatternSource::LetDecl(local),
-                        _ => return PatternSource::Other,
-                    }
-                }
-                _ => return PatternSource::Other,
-            }
-        }
-
+        NodeLocal(local) => PatternSource::LetDecl(local),
         _ => return PatternSource::Other,
 
     }
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 500fae4aff8..38336655f21 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -903,7 +903,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
 
     fn local_binding_mode(&self, node_id: ast::NodeId) -> ty::BindingMode {
         let pat = match self.tcx.hir.get(node_id) {
-            hir_map::Node::NodeLocal(pat) => pat,
+            hir_map::Node::NodeBinding(pat) => pat,
             node => bug!("bad node for local: {:?}", node)
         };
 
diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs
index 0c7a78c980a..d7a295a1c3a 100644
--- a/src/librustc_mir/build/mod.rs
+++ b/src/librustc_mir/build/mod.rs
@@ -382,7 +382,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
                 debug_name: keywords::Invalid.name(),
                 by_ref,
             };
-            if let Some(hir::map::NodeLocal(pat)) = tcx.hir.find(var_node_id) {
+            if let Some(hir::map::NodeBinding(pat)) = tcx.hir.find(var_node_id) {
                 if let hir::PatKind::Binding(_, _, ref ident, _) = pat.node {
                     decl.debug_name = ident.node;
                 }
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs
index ee14171e9a4..bc9d760d148 100644
--- a/src/librustc_save_analysis/lib.rs
+++ b/src/librustc_save_analysis/lib.rs
@@ -589,7 +589,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
                 self.tables.qpath_def(qpath, hir_id)
             }
 
-            Node::NodeLocal(&hir::Pat { node: hir::PatKind::Binding(_, def_id, ..), .. }) => {
+            Node::NodeBinding(&hir::Pat { node: hir::PatKind::Binding(_, def_id, ..), .. }) => {
                 HirDef::Local(def_id)
             }
 
diff --git a/src/test/run-pass/issue-43910.rs b/src/test/run-pass/issue-43910.rs
new file mode 100644
index 00000000000..d61ce7f4689
--- /dev/null
+++ b/src/test/run-pass/issue-43910.rs
@@ -0,0 +1,16 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![deny(unused_variables)]
+
+fn main() {
+    #[allow(unused_variables)]
+    let x = 12;
+}