]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/dataflow/impls/borrows.rs
Rollup merge of #64895 - davidtwco:issue-64130-async-error-definition, r=nikomatsakis
[rust.git] / src / librustc_mir / dataflow / impls / borrows.rs
index 10c3e52b5255a62464fc30009c12259d021ddcea..5e64144df2cd1c371d93d4b1b995017f191f3fd3 100644 (file)
@@ -2,12 +2,12 @@
 use crate::borrow_check::place_ext::PlaceExt;
 
 use rustc::mir::{self, Location, Place, PlaceBase, Body};
-use rustc::ty::TyCtxt;
+use rustc::ty::{self, TyCtxt};
 use rustc::ty::RegionVid;
 
-use rustc_data_structures::bit_set::BitSet;
+use rustc_index::bit_set::BitSet;
 use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::indexed_vec::{Idx, IndexVec};
+use rustc_index::vec::{Idx, IndexVec};
 
 use crate::dataflow::{BitDenotation, BottomValue, GenKillSet};
 use crate::borrow_check::nll::region_infer::RegionInferenceContext;
@@ -16,7 +16,7 @@
 
 use std::rc::Rc;
 
-newtype_index! {
+rustc_index::newtype_index! {
     pub struct BorrowIndex {
         DEBUG_FORMAT = "bw{}"
     }
@@ -32,6 +32,7 @@ pub struct BorrowIndex {
 pub struct Borrows<'a, 'tcx> {
     tcx: TyCtxt<'tcx>,
     body: &'a Body<'tcx>,
+    param_env: ty::ParamEnv<'tcx>,
 
     borrow_set: Rc<BorrowSet<'tcx>>,
     borrows_out_of_scope_at_location: FxHashMap<Location, Vec<BorrowIndex>>,
@@ -137,6 +138,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
     crate fn new(
         tcx: TyCtxt<'tcx>,
         body: &'a Body<'tcx>,
+        param_env: ty::ParamEnv<'tcx>,
         nonlexical_regioncx: Rc<RegionInferenceContext<'tcx>>,
         borrow_set: &Rc<BorrowSet<'tcx>>,
     ) -> Self {
@@ -153,6 +155,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
         Borrows {
             tcx: tcx,
             body: body,
+            param_env,
             borrow_set: borrow_set.clone(),
             borrows_out_of_scope_at_location,
             _nonlexical_regioncx: nonlexical_regioncx,
@@ -205,7 +208,7 @@ fn kill_borrows_on_place(
             // If the borrowed place is a local with no projections, all other borrows of this
             // local must conflict. This is purely an optimization so we don't have to call
             // `places_conflict` for every borrow.
-            if place.projection.is_none() {
+            if place.projection.is_empty() {
                 trans.kill_all(other_borrows_of_local);
                 return;
             }
@@ -218,6 +221,7 @@ fn kill_borrows_on_place(
                 .filter(|&&i| {
                     places_conflict::places_conflict(
                         self.tcx,
+                        self.param_env,
                         self.body,
                         &self.borrow_set.borrows[i].borrowed_place,
                         place,
@@ -264,12 +268,8 @@ fn statement_effect(&self,
 
         debug!("Borrows::statement_effect: stmt={:?}", stmt);
         match stmt.kind {
-            mir::StatementKind::Assign(ref lhs, ref rhs) => {
-                // Make sure there are no remaining borrows for variables
-                // that are assigned over.
-                self.kill_borrows_on_place(trans, lhs);
-
-                if let mir::Rvalue::Ref(_, _, ref place) = **rhs {
+            mir::StatementKind::Assign(box(ref lhs, ref rhs)) => {
+                if let mir::Rvalue::Ref(_, _, ref place) = *rhs {
                     if place.ignore_borrow(
                         self.tcx,
                         self.body,
@@ -283,6 +283,10 @@ fn statement_effect(&self,
 
                     trans.gen(*index);
                 }
+
+                // Make sure there are no remaining borrows for variables
+                // that are assigned over.
+                self.kill_borrows_on_place(trans, lhs);
             }
 
             mir::StatementKind::StorageDead(local) => {