]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/borrow_set.rs
Auto merge of #57609 - matthewjasper:more-restrictive-match, r=pnkfelix
[rust.git] / src / librustc_mir / borrow_check / borrow_set.rs
index 2788f5d4325a962e6af1560703c9fa9cb2123c8f..2a3a616317c172a86692d4eb7ab35545f3d44a08 100644 (file)
@@ -3,9 +3,7 @@
 use crate::dataflow::indexes::BorrowIndex;
 use crate::dataflow::move_paths::MoveData;
 use rustc::mir::traversal;
-use rustc::mir::visit::{
-    PlaceContext, Visitor, NonUseContext, MutatingUseContext, NonMutatingUseContext
-};
+use rustc::mir::visit::{PlaceContext, Visitor, NonUseContext, MutatingUseContext};
 use rustc::mir::{self, Location, Mir, Local};
 use rustc::ty::{RegionVid, TyCtxt};
 use rustc::util::nodemap::{FxHashMap, FxHashSet};
     crate location_map: FxHashMap<Location, BorrowIndex>,
 
     /// Locations which activate borrows.
-    /// NOTE: A given location may activate more than one borrow in the future
+    /// NOTE: a given location may activate more than one borrow in the future
     /// when more general two-phase borrow support is introduced, but for now we
-    /// only need to store one borrow index
+    /// only need to store one borrow index.
     crate activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
 
-    /// Map from local to all the borrows on that local
+    /// Map from local to all the borrows on that local.
     crate local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
 
     crate locals_state_at_exit: LocalsStateAtExit,
@@ -45,8 +43,8 @@ fn index(&self, index: BorrowIndex) -> &BorrowData<'tcx> {
     }
 }
 
-/// Location where a two phase borrow is activated, if a borrow
-/// is in fact a two phase borrow.
+/// Location where a two-phase borrow is activated, if a borrow
+/// is in fact a two-phase borrow.
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 crate enum TwoPhaseActivation {
     NotTwoPhase,
@@ -257,31 +255,21 @@ fn visit_local(
                 );
             }
 
-            // Otherwise, this is the unique later use
-            // that we expect.
-            borrow_data.activation_location = match context {
-                // The use of TMP in a shared borrow does not
-                // count as an actual activation.
-                PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
-                PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) =>
-                    TwoPhaseActivation::NotActivated,
-                _ => {
-                    // Double check: This borrow is indeed a two-phase borrow (that is,
-                    // we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
-                    // we've not found any other activations (checked above).
-                    assert_eq!(
-                        borrow_data.activation_location,
-                        TwoPhaseActivation::NotActivated,
-                        "never found an activation for this borrow!",
-                    );
-
-                    self.activation_map
-                        .entry(location)
-                        .or_default()
-                        .push(borrow_index);
-                    TwoPhaseActivation::ActivatedAt(location)
-                }
-            };
+            // Otherwise, this is the unique later use that we expect.
+            // Double check: This borrow is indeed a two-phase borrow (that is,
+            // we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
+            // we've not found any other activations (checked above).
+            assert_eq!(
+                borrow_data.activation_location,
+                TwoPhaseActivation::NotActivated,
+                "never found an activation for this borrow!",
+            );
+            self.activation_map
+                .entry(location)
+                .or_default()
+                .push(borrow_index);
+
+            borrow_data.activation_location = TwoPhaseActivation::ActivatedAt(location);
         }
     }
 
@@ -311,7 +299,7 @@ fn visit_statement(
 }
 
 impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
-    /// Returns true if the borrow represented by `kind` is
+    /// Returns `true` if the borrow represented by `kind` is
     /// allowed to be split into separate Reservation and
     /// Activation phases.
     fn allow_two_phase_borrow(&self, kind: mir::BorrowKind) -> bool {