about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-08-07 15:06:10 +0200
committerMichael Woerister <michaelwoerister@posteo>2017-08-11 12:11:38 +0200
commite777189b4accdd7a92adf8554a368d399ff7f3ee (patch)
tree1715374707f5b8186437caa223f104c60a930131
parent7f2423eede51cc622420356988777db2473a0be2 (diff)
downloadrust-e777189b4accdd7a92adf8554a368d399ff7f3ee.tar.gz
rust-e777189b4accdd7a92adf8554a368d399ff7f3ee.zip
Use ItemLocalId as key for TypeckTables::pat_binding_modes.
-rw-r--r--src/librustc/ich/impls_ty.rs2
-rw-r--r--src/librustc/middle/expr_use_visitor.rs7
-rw-r--r--src/librustc/middle/mem_categorization.rs13
-rw-r--r--src/librustc/ty/context.rs4
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs9
-rw-r--r--src/librustc_const_eval/check_match.rs20
-rw-r--r--src/librustc_const_eval/pattern.rs2
-rw-r--r--src/librustc_lint/unused.rs4
-rw-r--r--src/librustc_typeck/check/_match.rs7
-rw-r--r--src/librustc_typeck/check/regionck.rs3
-rw-r--r--src/librustc_typeck/check/writeback.rs11
11 files changed, 62 insertions, 20 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs
index ab505141880..21d797d1e9a 100644
--- a/src/librustc/ich/impls_ty.rs
+++ b/src/librustc/ich/impls_ty.rs
@@ -642,7 +642,7 @@ for ty::TypeckTables<'gcx> {
             ich::hash_stable_itemlocalmap(hcx, hasher, node_types);
             ich::hash_stable_itemlocalmap(hcx, hasher, node_substs);
             ich::hash_stable_itemlocalmap(hcx, hasher, adjustments);
-            ich::hash_stable_nodemap(hcx, hasher, pat_binding_modes);
+            ich::hash_stable_itemlocalmap(hcx, hasher, pat_binding_modes);
             ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
                 let ty::UpvarId {
                     var_id,
diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs
index b44f1c7da73..a11511c2434 100644
--- a/src/librustc/middle/expr_use_visitor.rs
+++ b/src/librustc/middle/expr_use_visitor.rs
@@ -797,7 +797,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
                pat);
         return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |cmt_pat, pat| {
             if let PatKind::Binding(..) = pat.node {
-                let bm = *self.mc.tables.pat_binding_modes.get(&pat.id)
+                self.mc.tables.validate_hir_id(pat.hir_id);
+                let bm = *self.mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
                                                           .expect("missing binding mode");
                 match bm {
                     ty::BindByReference(..) =>
@@ -823,7 +824,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
         return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
             if let PatKind::Binding(_, def_id, ..) = pat.node {
                 debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
-                let bm = *mc.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode");
+                mc.tables.validate_hir_id(pat.hir_id);
+                let bm = *mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
+                                                     .expect("missing binding mode");
 
                 // pat_ty: the type of the binding being produced.
                 let pat_ty = return_if_err!(mc.node_ty(pat.hir_id));
diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs
index 7a949cf38b3..faa91d0fa3a 100644
--- a/src/librustc/middle/mem_categorization.rs
+++ b/src/librustc/middle/mem_categorization.rs
@@ -334,7 +334,11 @@ impl MutabilityCategory {
         let ret = match tcx.hir.get(id) {
             hir_map::NodeLocal(p) => match p.node {
                 PatKind::Binding(..) => {
-                    let bm = *tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
+
+                    tables.validate_hir_id(p.hir_id);
+                    let bm = *tables.pat_binding_modes
+                                    .get(&p.hir_id.local_id)
+                                    .expect("missing binding mode");
                     if bm == ty::BindByValue(hir::MutMutable) {
                         McDeclared
                     } else {
@@ -481,7 +485,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
         // fundamental fix to this conflated use of the node id.
         let ret_ty = match pat.node {
             PatKind::Binding(..) => {
-                let bm = *self.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode");
+                self.tables.validate_hir_id(pat.hir_id);
+                let bm = *self.tables
+                              .pat_binding_modes
+                              .get(&pat.hir_id.local_id)
+                              .expect("missing binding mode");
+
                 if let ty::BindByReference(_) = bm {
                     // a bind-by-ref means that the base_ty will be the type of the ident itself,
                     // but what we want here is the type of the underlying value being borrowed.
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 528fb4e2e7f..d4ff1590e8a 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -230,7 +230,7 @@ pub struct TypeckTables<'tcx> {
     pub adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
 
     // Stores the actual binding mode for all instances of hir::BindingAnnotation.
-    pub pat_binding_modes: NodeMap<BindingMode>,
+    pub pat_binding_modes: ItemLocalMap<BindingMode>,
 
     /// Borrows
     pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
@@ -281,7 +281,7 @@ impl<'tcx> TypeckTables<'tcx> {
             node_types: ItemLocalMap(),
             node_substs: ItemLocalMap(),
             adjustments: ItemLocalMap(),
-            pat_binding_modes: NodeMap(),
+            pat_binding_modes: ItemLocalMap(),
             upvar_capture_map: FxHashMap(),
             closure_tys: NodeMap(),
             closure_kinds: NodeMap(),
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 6b31535c5a5..4b26aa95759 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -899,8 +899,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
         };
 
         match pat.node {
-            hir::PatKind::Binding(..) =>
-                *self.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode"),
+            hir::PatKind::Binding(..) => {
+                self.tables.validate_hir_id(pat.hir_id);
+                *self.tables
+                     .pat_binding_modes
+                     .get(&pat.hir_id.local_id)
+                     .expect("missing binding mode")
+            }
             _ => bug!("local is not a binding: {:?}", pat)
         }
     }
diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs
index 0d92bff02b1..a990670f08b 100644
--- a/src/librustc_const_eval/check_match.rs
+++ b/src/librustc_const_eval/check_match.rs
@@ -269,7 +269,12 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
 fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
     pat.walk(|p| {
         if let PatKind::Binding(_, _, name, None) = p.node {
-            let bm = *cx.tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
+            cx.tables.validate_hir_id(p.hir_id);
+            let bm = *cx.tables
+                        .pat_binding_modes
+                        .get(&p.hir_id.local_id)
+                        .expect("missing binding mode");
+
             if bm != ty::BindByValue(hir::MutImmutable) {
                 // Nothing to check.
                 return true;
@@ -458,7 +463,12 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
     let mut by_ref_span = None;
     for pat in pats {
         pat.each_binding(|_, id, span, _path| {
-            let bm = *cx.tables.pat_binding_modes.get(&id).expect("missing binding mode");
+            let hir_id = cx.tcx.hir.node_to_hir_id(id);
+            cx.tables.validate_hir_id(hir_id);
+            let bm = *cx.tables
+                        .pat_binding_modes
+                        .get(&hir_id.local_id)
+                        .expect("missing binding mode");
             if let ty::BindByReference(..) = bm {
                 by_ref_span = Some(span);
             }
@@ -491,7 +501,11 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
     for pat in pats {
         pat.walk(|p| {
             if let PatKind::Binding(_, _, _, ref sub) = p.node {
-                let bm = *cx.tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
+                cx.tables.validate_hir_id(p.hir_id);
+                let bm = *cx.tables
+                            .pat_binding_modes
+                            .get(&p.hir_id.local_id)
+                            .expect("missing binding mode");
                 match bm {
                     ty::BindByValue(..) => {
                         let pat_ty = cx.tables.node_id_to_type(p.hir_id);
diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs
index bad9895420a..924193786c1 100644
--- a/src/librustc_const_eval/pattern.rs
+++ b/src/librustc_const_eval/pattern.rs
@@ -381,7 +381,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
                     ty::TyRef(r, _) => Some(r),
                     _ => None,
                 };
-                let bm = *self.tables.pat_binding_modes.get(&pat.id)
+                let bm = *self.tables.pat_binding_modes.get(&pat.hir_id.local_id)
                                                        .expect("missing binding mode");
                 let (mutability, mode) = match bm {
                     ty::BindByValue(hir::MutMutable) =>
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index ba17df4cdca..f8f91e6c29d 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -45,7 +45,9 @@ impl UnusedMut {
         let mut mutables = FxHashMap();
         for p in pats {
             p.each_binding(|_, id, span, path1| {
-                let bm = match cx.tables.pat_binding_modes.get(&id) {
+                let hir_id = cx.tcx.hir.node_to_hir_id(id);
+                cx.tables.validate_hir_id(hir_id);
+                let bm = match cx.tables.pat_binding_modes.get(&hir_id.local_id) {
                     Some(&bm) => bm,
                     None => span_bug!(span, "missing binding mode"),
                 };
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index e1ced048870..3a616dadc42 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -118,8 +118,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 // identical to what could be scraped from the HIR, but this will change with
                 // default binding modes (#42640).
                 let bm = ty::BindingMode::convert(ba);
-                self.inh.tables.borrow_mut().pat_binding_modes.insert(pat.id, bm);
-
+                {
+                    let mut inh_tables = self.inh.tables.borrow_mut();
+                    inh_tables.validate_hir_id(pat.hir_id);
+                    inh_tables.pat_binding_modes.insert(pat.hir_id.local_id, bm);
+                }
                 let typ = self.local_ty(pat.span, pat.id);
                 match bm {
                     ty::BindByReference(mutbl) => {
diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs
index d88ed888338..3113f4a569f 100644
--- a/src/librustc_typeck/check/regionck.rs
+++ b/src/librustc_typeck/check/regionck.rs
@@ -1205,7 +1205,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
                 match sub_pat.node {
                     // `ref x` pattern
                     PatKind::Binding(..) => {
-                        let bm = *mc.tables.pat_binding_modes.get(&sub_pat.id)
+                        mc.tables.validate_hir_id(sub_pat.hir_id);
+                        let bm = *mc.tables.pat_binding_modes.get(&sub_pat.hir_id.local_id)
                                                              .expect("missing binding mode");
                         if let ty::BindByReference(mutbl) = bm {
                             self.link_region_from_node_type(sub_pat.span, sub_pat.hir_id,
diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs
index 058cef71d4a..b689da6e386 100644
--- a/src/librustc_typeck/check/writeback.rs
+++ b/src/librustc_typeck/check/writeback.rs
@@ -186,9 +186,14 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
     fn visit_pat(&mut self, p: &'gcx hir::Pat) {
         match p.node {
             hir::PatKind::Binding(..) => {
-                let bm = *self.fcx.tables.borrow().pat_binding_modes.get(&p.id)
-                                                                    .expect("missing binding mode");
-                self.tables.pat_binding_modes.insert(p.id, bm);
+                let bm = {
+                    let fcx_tables = self.fcx.tables.borrow();
+                    fcx_tables.validate_hir_id(p.hir_id);
+                    *fcx_tables.pat_binding_modes.get(&p.hir_id.local_id)
+                                                 .expect("missing binding mode")
+                };
+                self.tables.validate_hir_id(p.hir_id);
+                self.tables.pat_binding_modes.insert(p.hir_id.local_id, bm);
             }
             _ => {}
         };