1
Fork 0

Avoid cloning Place in append_place_to_string

This commit is contained in:
Santiago Pastorino 2019-07-19 19:55:49 +02:00
parent 72251d5595
commit 34e3b7076c

View file

@ -272,9 +272,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let name = self.upvars[var_index].name.to_string(); let name = self.upvars[var_index].name.to_string();
buf.push_str(&name); buf.push_str(&name);
} else { } else {
let field_name = self.describe_field(&Place { let field_name = self.describe_field(PlaceRef {
base: (*base).clone(), base: base,
projection: proj.base.clone(), projection: &proj.base,
}, field); }, field);
self.append_place_to_string( self.append_place_to_string(
PlaceRef { PlaceRef {
@ -343,31 +343,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
/// End-user visible description of the `field`nth field of `base` /// 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 // FIXME Place2 Make this work iteratively
match place { match place {
Place { PlaceRef {
base: PlaceBase::Local(local), base: PlaceBase::Local(local),
projection: None, projection: None,
} => { } => {
let local = &self.body.local_decls[*local]; let local = &self.body.local_decls[*local];
self.describe_field_from_ty(&local.ty, field, None) self.describe_field_from_ty(&local.ty, field, None)
} }
Place { PlaceRef {
base: PlaceBase::Static(static_), base: PlaceBase::Static(static_),
projection: None, projection: None,
} => } =>
self.describe_field_from_ty(&static_.ty, field, None), self.describe_field_from_ty(&static_.ty, field, None),
Place { PlaceRef {
base, base,
projection: Some(proj), projection: Some(proj),
} => match proj.elem { } => match proj.elem {
ProjectionElem::Deref => self.describe_field(&Place { ProjectionElem::Deref => self.describe_field(PlaceRef {
base: base.clone(), base,
projection: proj.base.clone(), projection: &proj.base,
}, field), }, field),
ProjectionElem::Downcast(_, variant_index) => { 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)) self.describe_field_from_ty(&base_ty, field, Some(variant_index))
} }
ProjectionElem::Field(_, field_type) => { ProjectionElem::Field(_, field_type) => {
@ -376,9 +377,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ProjectionElem::Index(..) ProjectionElem::Index(..)
| ProjectionElem::ConstantIndex { .. } | ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. } => { | ProjectionElem::Subslice { .. } => {
self.describe_field(&Place { self.describe_field(PlaceRef {
base: base.clone(), base,
projection: proj.base.clone(), projection: &proj.base,
}, field) }, field)
} }
}, },