Skip to content

Commit 34e3b70

Browse files
committed
Avoid cloning Place in append_place_to_string
1 parent 72251d5 commit 34e3b70

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
272272
let name = self.upvars[var_index].name.to_string();
273273
buf.push_str(&name);
274274
} else {
275-
let field_name = self.describe_field(&Place {
276-
base: (*base).clone(),
277-
projection: proj.base.clone(),
275+
let field_name = self.describe_field(PlaceRef {
276+
base: base,
277+
projection: &proj.base,
278278
}, field);
279279
self.append_place_to_string(
280280
PlaceRef {
@@ -343,31 +343,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
343343
}
344344

345345
/// End-user visible description of the `field`nth field of `base`
346-
fn describe_field(&self, place: &Place<'tcx>, field: Field) -> String {
346+
fn describe_field(&self, place: PlaceRef<'cx, 'tcx>, field: Field) -> String {
347347
// FIXME Place2 Make this work iteratively
348348
match place {
349-
Place {
349+
PlaceRef {
350350
base: PlaceBase::Local(local),
351351
projection: None,
352352
} => {
353353
let local = &self.body.local_decls[*local];
354354
self.describe_field_from_ty(&local.ty, field, None)
355355
}
356-
Place {
356+
PlaceRef {
357357
base: PlaceBase::Static(static_),
358358
projection: None,
359359
} =>
360360
self.describe_field_from_ty(&static_.ty, field, None),
361-
Place {
361+
PlaceRef {
362362
base,
363363
projection: Some(proj),
364364
} => match proj.elem {
365-
ProjectionElem::Deref => self.describe_field(&Place {
366-
base: base.clone(),
367-
projection: proj.base.clone(),
365+
ProjectionElem::Deref => self.describe_field(PlaceRef {
366+
base,
367+
projection: &proj.base,
368368
}, field),
369369
ProjectionElem::Downcast(_, variant_index) => {
370-
let base_ty = place.ty(self.body, self.infcx.tcx).ty;
370+
let base_ty =
371+
Place::ty_from(place.base, place.projection, self.body, self.infcx.tcx).ty;
371372
self.describe_field_from_ty(&base_ty, field, Some(variant_index))
372373
}
373374
ProjectionElem::Field(_, field_type) => {
@@ -376,9 +377,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
376377
ProjectionElem::Index(..)
377378
| ProjectionElem::ConstantIndex { .. }
378379
| ProjectionElem::Subslice { .. } => {
379-
self.describe_field(&Place {
380-
base: base.clone(),
381-
projection: proj.base.clone(),
380+
self.describe_field(PlaceRef {
381+
base,
382+
projection: &proj.base,
382383
}, field)
383384
}
384385
},

0 commit comments

Comments
 (0)