]> git.lizzy.rs Git - rust.git/commitdiff
capture_disjoint_fields(rust-lang#53488)
authorBlitzerr <rusty.blitzerr@gmail.com>
Thu, 15 Nov 2018 05:14:46 +0000 (21:14 -0800)
committerBlitzerr <rusty.blitzerr@gmail.com>
Thu, 15 Nov 2018 05:18:48 +0000 (21:18 -0800)
Refactoring out the HirId of the UpvarId in another struct.

15 files changed:
src/librustc/ich/impls_ty.rs
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/error_reporting/note.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/mem_categorization.rs
src/librustc/ty/context.rs
src/librustc/ty/mod.rs
src/librustc/util/ppaux.rs
src/librustc_borrowck/borrowck/gather_loans/mod.rs
src/librustc_borrowck/borrowck/gather_loans/move_error.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_mir/build/mod.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_typeck/check/upvar.rs
src/librustc_typeck/check/writeback.rs

index f3a62975dd9f4547eb254960fc8d605c5ffa9a36..928a6accf2d12abdaedb4883f4a57b7e1b7eb6d4 100644 (file)
@@ -216,7 +216,9 @@ fn hash_stable<W: StableHasherResult>(&self,
     }
 }
 
-impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
+impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
+
+impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
 
 impl_stable_hash_for!(enum ty::BorrowKind {
     ImmBorrow,
index f833ebc7ca763ec9ffab99f78e997de8249f35cc..59a490f4a013d9a6dc6dec97f74fcd682e149f44 100644 (file)
@@ -1315,7 +1315,7 @@ fn report_inference_failure(
                 format!(" for lifetime parameter `{}` in coherence check", name)
             }
             infer::UpvarRegion(ref upvar_id, _) => {
-                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
+                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
                 let var_name = self.tcx.hir.name(var_node_id);
                 format!(" for capture of `{}` by closure", var_name)
             }
index 54d01a035a8bee3a4750edef2435dae97b412f6f..a539c321af3f0be79cc570f22a72bd560d171a84 100644 (file)
@@ -41,7 +41,7 @@ pub(super) fn note_region_origin(&self,
                               "...so that reference does not outlive borrowed content");
             }
             infer::ReborrowUpvar(span, ref upvar_id) => {
-                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
+                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
                 let var_name = self.tcx.hir.name(var_node_id);
                 err.span_note(span,
                               &format!("...so that closure can access `{}`", var_name));
@@ -174,7 +174,7 @@ pub(super) fn report_concrete_failure(&self,
                 err
             }
             infer::ReborrowUpvar(span, ref upvar_id) => {
-                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
+                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
                 let var_name = self.tcx.hir.name(var_node_id);
                 let mut err = struct_span_err!(self.tcx.sess,
                                                span,
index 7e9b26bbf729c357a70ac32a9e0c3ed2426738d1..5b92bfe6ad3c48629a67600f4e5e45b91e84ff15 100644 (file)
@@ -938,7 +938,7 @@ fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
                 let var_hir_id = self.tcx().hir.node_to_hir_id(freevar.var_id());
                 let closure_def_id = self.tcx().hir.local_def_id(closure_expr.id);
                 let upvar_id = ty::UpvarId {
-                    var_id: var_hir_id,
+                    var_path: ty::UpvarPath { hir_id: var_hir_id },
                     closure_expr_id: closure_def_id.to_local(),
                 };
                 let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
index 59ef8fa14484b6837876aa25b56323df03e4e6f9..cadf0c42d228fe21575c5cf2dc5a68c8d95fce36 100644 (file)
@@ -818,7 +818,7 @@ fn cat_upvar(&self,
         let closure_expr_def_id = self.tcx.hir.local_def_id(fn_node_id);
         let var_hir_id = self.tcx.hir.node_to_hir_id(var_id);
         let upvar_id = ty::UpvarId {
-            var_id: var_hir_id,
+            var_path: ty::UpvarPath { hir_id: var_hir_id },
             closure_expr_id: closure_expr_def_id.to_local(),
         };
 
index cdfe8f53b854b96774f75a92b0c0bfcda80097e1..923d362c2345ff6a4fcdcdd163de411683463da4 100644 (file)
@@ -789,7 +789,7 @@ fn hash_stable<W: StableHasherResult>(&self,
             pat_adjustments.hash_stable(hcx, hasher);
             hash_stable_hashmap(hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
                 let ty::UpvarId {
-                    var_id,
+                    var_path,
                     closure_expr_id
                 } = *up_var_id;
 
@@ -798,14 +798,14 @@ fn hash_stable<W: StableHasherResult>(&self,
 
                 let var_owner_def_id = DefId {
                     krate: local_id_root.krate,
-                    index: var_id.owner,
+                    index: var_path.hir_id.owner,
                 };
                 let closure_def_id = DefId {
                     krate: local_id_root.krate,
                     index: closure_expr_id.to_def_id().index,
                 };
                 (hcx.def_path_hash(var_owner_def_id),
-                 var_id.local_id,
+                 var_path.hir_id.local_id,
                  hcx.def_path_hash(closure_def_id))
             });
 
index 8197136d189aec581ca0d286c1bdb0c66a24d7d3..d1497c42af78f1c9337ca3f48a5e83fbc99ca44a 100644 (file)
@@ -731,12 +731,17 @@ pub fn empty<'a>() -> &'a List<T> {
     }
 }
 
+#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
+pub struct UpvarPath {
+    pub hir_id: hir::HirId,
+}
+
 /// Upvars do not get their own node-id. Instead, we use the pair of
 /// the original var id (that is, the root variable that is referenced
 /// by the upvar) and the id of the closure expression.
 #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
 pub struct UpvarId {
-    pub var_id: hir::HirId,
+    pub var_path: UpvarPath,
     pub closure_expr_id: LocalDefId,
 }
 
index e44c0c05bb1a6c78fdc829f2f509cd002a5f3677..d53370d242bd94c842e2bdc3557470e4aeb06453 100644 (file)
@@ -678,8 +678,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl fmt::Debug for ty::UpvarId {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "UpvarId({:?};`{}`;{:?})",
-               self.var_id,
-               ty::tls::with(|tcx| tcx.hir.name(tcx.hir.hir_to_node_id(self.var_id))),
+               self.var_path.hir_id,
+               ty::tls::with(|tcx| tcx.hir.name(tcx.hir.hir_to_node_id(self.var_path.hir_id))),
                self.closure_expr_id)
     }
 }
index 78a31ed668fcae090b32f31f3fee1e1bd71fbeea..21fb0cdf90ad12306cfa346806ec747c9f0cc725 100644 (file)
@@ -453,8 +453,8 @@ pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) {
                     }
                     None
                 }
-                LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
-                    self.bccx.used_mut_nodes.borrow_mut().insert(var_id);
+                LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => {
+                    self.bccx.used_mut_nodes.borrow_mut().insert(hir_id);
                     None
                 }
                 LpExtend(ref base, mc::McInherited, LpDeref(pointer_kind)) |
index e1a4473539c8c567c531caabb8b167aebddcb805..cfd530b7e3d0924bc346687df631c92b8d05f657 100644 (file)
@@ -97,7 +97,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
             }
         }
         if let NoteClosureEnv(upvar_id) = error.move_from.note {
-            let var_node_id = bccx.tcx.hir.hir_to_node_id(upvar_id.var_id);
+            let var_node_id = bccx.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
             err.span_label(bccx.tcx.hir.span(var_node_id),
                            "captured outer variable");
         }
index d52d78181b77ab7dbd8f7ecfe56c6705b63c0117..d189460d088484af00d84dd6656a173266f5e39a 100644 (file)
@@ -846,7 +846,7 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
                     MutabilityViolation => {
                         let mut db = self.cannot_assign(error_span, &descr, Origin::Ast);
                         if let mc::NoteClosureEnv(upvar_id) = err.cmt.note {
-                            let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
+                            let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
                             let sp = self.tcx.hir.span(node_id);
                             let fn_closure_msg = "`Fn` closures cannot capture their enclosing \
                                                   environment for modifications";
@@ -1415,7 +1415,7 @@ pub fn append_loan_path_to_string(&self,
                                       loan_path: &LoanPath<'tcx>,
                                       out: &mut String) {
         match loan_path.kind {
-            LpUpvar(ty::UpvarId { var_id: id, closure_expr_id: _ }) => {
+            LpUpvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id: id}, closure_expr_id: _ }) => {
                 out.push_str(&self.tcx.hir.name(self.tcx.hir.hir_to_node_id(id)).as_str());
             }
             LpVar(id) => {
@@ -1533,7 +1533,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                 write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_string(id)))
             }
 
-            LpUpvar(ty::UpvarId{ var_id, closure_expr_id }) => {
+            LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => {
                 let s = ty::tls::with(|tcx| {
                     let var_node_id = tcx.hir.hir_to_node_id(var_id);
                     tcx.hir.node_to_string(var_node_id)
@@ -1568,9 +1568,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                 write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_user_string(id)))
             }
 
-            LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
+            LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => {
                 let s = ty::tls::with(|tcx| {
-                    let var_node_id = tcx.hir.hir_to_node_id(var_id);
+                    let var_node_id = tcx.hir.hir_to_node_id(hir_id);
                     tcx.hir.node_to_string(var_node_id)
                 });
                 write!(f, "$({} captured by closure)", s)
index 5b4001f0652ad9a0b4857ae53a856559f7eb21a3..94d1874e9c9e8c24bd859ab7ac9a6be35c2d301d 100644 (file)
@@ -612,7 +612,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
             let var_hir_id = tcx.hir.node_to_hir_id(var_id);
             let closure_expr_id = tcx.hir.local_def_id(fn_id);
             let capture = hir.tables().upvar_capture(ty::UpvarId {
-                var_id: var_hir_id,
+                var_path: ty::UpvarPath {hir_id: var_hir_id},
                 closure_expr_id: LocalDefId::from_def_id(closure_expr_id),
             });
             let by_ref = match capture {
index 656a467fb4912827fb5f560e73afcacbbea622f3..2e9edf20c5708f3e2dc966fd2d04a10f9d1fa44d 100644 (file)
@@ -1061,7 +1061,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
             // ...but the upvar might be an `&T` or `&mut T` capture, at which
             // point we need an implicit deref
             let upvar_id = ty::UpvarId {
-                var_id: var_hir_id,
+                var_path: ty::UpvarPath {hir_id: var_hir_id},
                 closure_expr_id: LocalDefId::from_def_id(closure_def_id),
             };
             match cx.tables().upvar_capture(upvar_id) {
@@ -1178,7 +1178,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
                                    -> ExprRef<'tcx> {
     let var_hir_id = cx.tcx.hir.node_to_hir_id(freevar.var_id());
     let upvar_id = ty::UpvarId {
-        var_id: var_hir_id,
+        var_path: ty::UpvarPath { hir_id: var_hir_id },
         closure_expr_id: cx.tcx.hir.local_def_id(closure_expr.id).to_local(),
     };
     let upvar_capture = cx.tables().upvar_capture(upvar_id);
index ef29e13d9fe123848e705abc7ddb8e93dbd65f75..312ce402775d226759853d2c424ace38fe65a373 100644 (file)
@@ -134,7 +134,9 @@ fn analyze_closure(
         self.tcx.with_freevars(closure_node_id, |freevars| {
             for freevar in freevars {
                 let upvar_id = ty::UpvarId {
-                    var_id: self.tcx.hir.node_to_hir_id(freevar.var_id()),
+                    var_path: ty::UpvarPath {
+                        hir_id : self.tcx.hir.node_to_hir_id(freevar.var_id()),
+                    },
                     closure_expr_id: LocalDefId::from_def_id(closure_def_id),
                 };
                 debug!("seed upvar_id {:?}", upvar_id);
@@ -248,7 +250,9 @@ fn final_upvar_tys(&self, closure_id: ast::NodeId) -> Vec<Ty<'tcx>> {
                     let var_hir_id = tcx.hir.node_to_hir_id(var_node_id);
                     let freevar_ty = self.node_ty(var_hir_id);
                     let upvar_id = ty::UpvarId {
-                        var_id: var_hir_id,
+                        var_path: ty::UpvarPath {
+                            hir_id: var_hir_id,
+                        },
                         closure_expr_id: LocalDefId::from_def_id(closure_def_index),
                     };
                     let capture = self.tables.borrow().upvar_capture(upvar_id);
@@ -347,7 +351,7 @@ fn adjust_upvar_borrow_kind_for_consume(
                         upvar_id.closure_expr_id,
                         ty::ClosureKind::FnOnce,
                         guarantor.span,
-                        var_name(tcx, upvar_id.var_id),
+                        var_name(tcx, upvar_id.var_path.hir_id),
                     );
 
                     self.adjust_upvar_captures
@@ -364,7 +368,7 @@ fn adjust_upvar_borrow_kind_for_consume(
                         upvar_id.closure_expr_id,
                         ty::ClosureKind::FnOnce,
                         guarantor.span,
-                        var_name(tcx, upvar_id.var_id),
+                        var_name(tcx, upvar_id.var_path.hir_id),
                     );
                 }
                 mc::NoteIndex | mc::NoteNone => {}
@@ -465,7 +469,7 @@ fn try_adjust_upvar_deref(
                     upvar_id.closure_expr_id,
                     ty::ClosureKind::FnMut,
                     cmt.span,
-                    var_name(tcx, upvar_id.var_id),
+                    var_name(tcx, upvar_id.var_path.hir_id),
                 );
 
                 true
@@ -478,7 +482,7 @@ fn try_adjust_upvar_deref(
                     upvar_id.closure_expr_id,
                     ty::ClosureKind::FnMut,
                     cmt.span,
-                    var_name(tcx, upvar_id.var_id),
+                    var_name(tcx, upvar_id.var_path.hir_id),
                 );
 
                 true
index d968bf222aa0983ef9e2674a0fde46f19d3f1ac4..4460d5f64ce26283e7d93e99dd29622b8a7fa941 100644 (file)
@@ -306,7 +306,7 @@ fn visit_upvar_borrow_map(&mut self) {
                 ty::UpvarCapture::ByValue => ty::UpvarCapture::ByValue,
                 ty::UpvarCapture::ByRef(ref upvar_borrow) => {
                     let r = upvar_borrow.region;
-                    let r = self.resolve(&r, &upvar_id.var_id);
+                    let r = self.resolve(&r, &upvar_id.var_path.hir_id);
                     ty::UpvarCapture::ByRef(ty::UpvarBorrow {
                         kind: upvar_borrow.kind,
                         region: r,