about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2019-07-19 19:55:49 +0200
committerSantiago Pastorino <spastorino@gmail.com>2019-07-20 05:08:39 +0200
commit34e3b7076c216413f39bf28bfea76f9a72b96cbb (patch)
tree4b813bd068b5c4c2ba763d9485842df9602fa4f4
parent72251d5595ca4f5e7a57ab6f0db0d0a498d5b737 (diff)
downloadrust-34e3b7076c216413f39bf28bfea76f9a72b96cbb.tar.gz
rust-34e3b7076c216413f39bf28bfea76f9a72b96cbb.zip
Avoid cloning Place in append_place_to_string
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index 06ef802a4cf..10b283b16bf 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -272,9 +272,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                             let name = self.upvars[var_index].name.to_string();
                             buf.push_str(&name);
                         } else {
-                            let field_name = self.describe_field(&Place {
-                                base: (*base).clone(),
-                                projection: proj.base.clone(),
+                            let field_name = self.describe_field(PlaceRef {
+                                base: base,
+                                projection: &proj.base,
                             }, field);
                             self.append_place_to_string(
                                 PlaceRef {
@@ -343,31 +343,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
     }
 
     /// End-user visible description of the `field`nth field of `base`
-    fn describe_field(&self, place: &Place<'tcx>, field: Field) -> String {
+    fn describe_field(&self, place: PlaceRef<'cx, 'tcx>, field: Field) -> String {
         // FIXME Place2 Make this work iteratively
         match place {
-            Place {
+            PlaceRef {
                 base: PlaceBase::Local(local),
                 projection: None,
             } => {
                 let local = &self.body.local_decls[*local];
                 self.describe_field_from_ty(&local.ty, field, None)
             }
-            Place {
+            PlaceRef {
                 base: PlaceBase::Static(static_),
                 projection: None,
             } =>
                 self.describe_field_from_ty(&static_.ty, field, None),
-            Place {
+            PlaceRef {
                 base,
                 projection: Some(proj),
             } => match proj.elem {
-                ProjectionElem::Deref => self.describe_field(&Place {
-                    base: base.clone(),
-                    projection: proj.base.clone(),
+                ProjectionElem::Deref => self.describe_field(PlaceRef {
+                    base,
+                    projection: &proj.base,
                 }, field),
                 ProjectionElem::Downcast(_, variant_index) => {
-                    let base_ty = place.ty(self.body, self.infcx.tcx).ty;
+                    let base_ty =
+                        Place::ty_from(place.base, place.projection, self.body, self.infcx.tcx).ty;
                     self.describe_field_from_ty(&base_ty, field, Some(variant_index))
                 }
                 ProjectionElem::Field(_, field_type) => {
@@ -376,9 +377,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                 ProjectionElem::Index(..)
                 | ProjectionElem::ConstantIndex { .. }
                 | ProjectionElem::Subslice { .. } => {
-                    self.describe_field(&Place {
-                        base: base.clone(),
-                        projection: proj.base.clone(),
+                    self.describe_field(PlaceRef {
+                        base,
+                        projection: &proj.base,
                     }, field)
                 }
             },