about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2019-07-19 21:33:13 +0200
committerSantiago Pastorino <spastorino@gmail.com>2019-07-20 05:08:39 +0200
commitd77653e88bc552944cac2eca4a880b6ee8abc9a2 (patch)
tree9689cb3bb02cc7fc40db3608c681991373cc39dd
parent2ffd3c64f9a55c675fc5e0efd88c309dbe6e8ee3 (diff)
downloadrust-d77653e88bc552944cac2eca4a880b6ee8abc9a2.tar.gz
rust-d77653e88bc552944cac2eca4a880b6ee8abc9a2.zip
Avoid cloning Place in calculate_fake_borrows
-rw-r--r--src/librustc/mir/mod.rs2
-rw-r--r--src/librustc_mir/build/matches/mod.rs25
2 files changed, 18 insertions, 9 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index b113f87fb86..d8b641fbe31 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -1826,7 +1826,7 @@ newtype_index! {
     }
 }
 
-#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub struct PlaceRef<'a, 'tcx> {
     pub base: &'a PlaceBase<'tcx>,
     pub projection: &'a Option<Box<Projection<'tcx>>>,
diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs
index 5e3acd9fa8e..b58cef9cce1 100644
--- a/src/librustc_mir/build/matches/mod.rs
+++ b/src/librustc_mir/build/matches/mod.rs
@@ -1280,7 +1280,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         &mut self,
         fake_borrows: &'b FxHashSet<Place<'tcx>>,
         temp_span: Span,
-    ) -> Vec<(Place<'tcx>, Local)> {
+    ) -> Vec<(PlaceRef<'b, 'tcx>, Local)> {
         let tcx = self.hir.tcx();
 
         debug!("add_fake_borrows fake_borrows = {:?}", fake_borrows);
@@ -1296,15 +1296,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     // Insert a shallow borrow after a deref. For other
                     // projections the borrow of prefix_cursor will
                     // conflict with any mutation of base.
-                    all_fake_borrows.push(Place {
-                        base: place.base.clone(),
-                        projection: base.clone(),
+                    all_fake_borrows.push(PlaceRef {
+                        base: &place.base,
+                        projection: base,
                     });
                 }
                 prefix_cursor = base;
             }
 
-            all_fake_borrows.push(place.clone());
+            all_fake_borrows.push(place.as_place_ref());
         }
 
         // Deduplicate and ensure a deterministic order.
@@ -1314,7 +1314,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);
 
         all_fake_borrows.into_iter().map(|matched_place| {
-            let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty;
+            let fake_borrow_deref_ty = Place::ty_from(
+                matched_place.base,
+                matched_place.projection,
+                &self.local_decls,
+                tcx,
+            )
+            .ty;
             let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty);
             let fake_borrow_temp = self.local_decls.push(
                 LocalDecl::new_temp(fake_borrow_ty, temp_span)
@@ -1345,7 +1351,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         &mut self,
         candidate: Candidate<'pat, 'tcx>,
         guard: Option<Guard<'tcx>>,
-        fake_borrows: &Vec<(Place<'tcx>, Local)>,
+        fake_borrows: &Vec<(PlaceRef<'_, 'tcx>, Local)>,
         scrutinee_span: Span,
         region_scope: region::Scope,
     ) -> BasicBlock {
@@ -1480,7 +1486,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 let borrow = Rvalue::Ref(
                     re_erased,
                     BorrowKind::Shallow,
-                    place.clone(),
+                    Place {
+                        base: place.base.clone(),
+                        projection: place.projection.clone(),
+                    },
                 );
                 self.cfg.push_assign(
                     block,