1
Fork 0

Avoid cloning Place in in_projection_structurally

This commit is contained in:
Santiago Pastorino 2019-07-19 22:18:03 +02:00
parent 7b456df4ab
commit 2a7d600ee0

View file

@ -185,9 +185,9 @@ trait Qualif {
base: &PlaceBase<'tcx>, base: &PlaceBase<'tcx>,
proj: &Projection<'tcx>, proj: &Projection<'tcx>,
) -> bool { ) -> bool {
let base_qualif = Self::in_place(cx, &Place { let base_qualif = Self::in_place(cx, PlaceRef {
base: base.clone(), base,
projection: proj.base.clone(), projection: &proj.base,
}); });
let qualif = base_qualif && Self::mask_for_ty( let qualif = base_qualif && Self::mask_for_ty(
cx, cx,
@ -214,36 +214,36 @@ trait Qualif {
Self::in_projection_structurally(cx, base, proj) Self::in_projection_structurally(cx, base, proj)
} }
fn in_place(cx: &ConstCx<'_, 'tcx>, place: &Place<'tcx>) -> bool { fn in_place(cx: &ConstCx<'_, 'tcx>, place: PlaceRef<'_, 'tcx>) -> bool {
match *place { match place {
Place { PlaceRef {
base: PlaceBase::Local(local), base: PlaceBase::Local(local),
projection: None, projection: None,
} => Self::in_local(cx, local), } => Self::in_local(cx, *local),
Place { PlaceRef {
base: PlaceBase::Static(box Static { base: PlaceBase::Static(box Static {
kind: StaticKind::Promoted(_), kind: StaticKind::Promoted(_),
.. ..
}), }),
projection: None, projection: None,
} => bug!("qualifying already promoted MIR"), } => bug!("qualifying already promoted MIR"),
Place { PlaceRef {
base: PlaceBase::Static(ref static_), base: PlaceBase::Static(static_),
projection: None, projection: None,
} => { } => {
Self::in_static(cx, static_) Self::in_static(cx, static_)
}, },
Place { PlaceRef {
ref base, base,
projection: Some(ref proj), projection: Some(proj),
} => Self::in_projection(cx, &base, proj), } => Self::in_projection(cx, base, proj),
} }
} }
fn in_operand(cx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>) -> bool { fn in_operand(cx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>) -> bool {
match *operand { match *operand {
Operand::Copy(ref place) | Operand::Copy(ref place) |
Operand::Move(ref place) => Self::in_place(cx, place), Operand::Move(ref place) => Self::in_place(cx, place.as_place_ref()),
Operand::Constant(ref constant) => { Operand::Constant(ref constant) => {
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val { if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
@ -272,7 +272,7 @@ trait Qualif {
Rvalue::NullaryOp(..) => false, Rvalue::NullaryOp(..) => false,
Rvalue::Discriminant(ref place) | Rvalue::Discriminant(ref place) |
Rvalue::Len(ref place) => Self::in_place(cx, place), Rvalue::Len(ref place) => Self::in_place(cx, place.as_place_ref()),
Rvalue::Use(ref operand) | Rvalue::Use(ref operand) |
Rvalue::Repeat(ref operand, _) | Rvalue::Repeat(ref operand, _) |
@ -290,15 +290,15 @@ trait Qualif {
if let ProjectionElem::Deref = proj.elem { if let ProjectionElem::Deref = proj.elem {
let base_ty = Place::ty_from(&place.base, &proj.base, cx.body, cx.tcx).ty; let base_ty = Place::ty_from(&place.base, &proj.base, cx.body, cx.tcx).ty;
if let ty::Ref(..) = base_ty.sty { if let ty::Ref(..) = base_ty.sty {
return Self::in_place(cx, &Place { return Self::in_place(cx, PlaceRef {
base: place.base.clone(), base: &place.base,
projection: proj.base.clone(), projection: &proj.base,
}); });
} }
} }
} }
Self::in_place(cx, place) Self::in_place(cx, place.as_place_ref())
} }
Rvalue::Aggregate(_, ref operands) => { Rvalue::Aggregate(_, ref operands) => {