Skip to content

Commit 2a7d600

Browse files
committed
Avoid cloning Place in in_projection_structurally
1 parent 7b456df commit 2a7d600

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/librustc_mir/transform/qualify_consts.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ trait Qualif {
185185
base: &PlaceBase<'tcx>,
186186
proj: &Projection<'tcx>,
187187
) -> bool {
188-
let base_qualif = Self::in_place(cx, &Place {
189-
base: base.clone(),
190-
projection: proj.base.clone(),
188+
let base_qualif = Self::in_place(cx, PlaceRef {
189+
base,
190+
projection: &proj.base,
191191
});
192192
let qualif = base_qualif && Self::mask_for_ty(
193193
cx,
@@ -214,36 +214,36 @@ trait Qualif {
214214
Self::in_projection_structurally(cx, base, proj)
215215
}
216216

217-
fn in_place(cx: &ConstCx<'_, 'tcx>, place: &Place<'tcx>) -> bool {
218-
match *place {
219-
Place {
217+
fn in_place(cx: &ConstCx<'_, 'tcx>, place: PlaceRef<'_, 'tcx>) -> bool {
218+
match place {
219+
PlaceRef {
220220
base: PlaceBase::Local(local),
221221
projection: None,
222-
} => Self::in_local(cx, local),
223-
Place {
222+
} => Self::in_local(cx, *local),
223+
PlaceRef {
224224
base: PlaceBase::Static(box Static {
225225
kind: StaticKind::Promoted(_),
226226
..
227227
}),
228228
projection: None,
229229
} => bug!("qualifying already promoted MIR"),
230-
Place {
231-
base: PlaceBase::Static(ref static_),
230+
PlaceRef {
231+
base: PlaceBase::Static(static_),
232232
projection: None,
233233
} => {
234234
Self::in_static(cx, static_)
235235
},
236-
Place {
237-
ref base,
238-
projection: Some(ref proj),
239-
} => Self::in_projection(cx, &base, proj),
236+
PlaceRef {
237+
base,
238+
projection: Some(proj),
239+
} => Self::in_projection(cx, base, proj),
240240
}
241241
}
242242

243243
fn in_operand(cx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>) -> bool {
244244
match *operand {
245245
Operand::Copy(ref place) |
246-
Operand::Move(ref place) => Self::in_place(cx, place),
246+
Operand::Move(ref place) => Self::in_place(cx, place.as_place_ref()),
247247

248248
Operand::Constant(ref constant) => {
249249
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
@@ -272,7 +272,7 @@ trait Qualif {
272272
Rvalue::NullaryOp(..) => false,
273273

274274
Rvalue::Discriminant(ref place) |
275-
Rvalue::Len(ref place) => Self::in_place(cx, place),
275+
Rvalue::Len(ref place) => Self::in_place(cx, place.as_place_ref()),
276276

277277
Rvalue::Use(ref operand) |
278278
Rvalue::Repeat(ref operand, _) |
@@ -290,15 +290,15 @@ trait Qualif {
290290
if let ProjectionElem::Deref = proj.elem {
291291
let base_ty = Place::ty_from(&place.base, &proj.base, cx.body, cx.tcx).ty;
292292
if let ty::Ref(..) = base_ty.sty {
293-
return Self::in_place(cx, &Place {
294-
base: place.base.clone(),
295-
projection: proj.base.clone(),
293+
return Self::in_place(cx, PlaceRef {
294+
base: &place.base,
295+
projection: &proj.base,
296296
});
297297
}
298298
}
299299
}
300300

301-
Self::in_place(cx, place)
301+
Self::in_place(cx, place.as_place_ref())
302302
}
303303

304304
Rvalue::Aggregate(_, ref operands) => {

0 commit comments

Comments
 (0)