Skip to content

Commit 9b549d3

Browse files
committed
Avoid cloning Place in gather_init
1 parent d77653e commit 9b549d3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
274274
// move-path for the interior so it will be separate from
275275
// the exterior.
276276
self.create_move_path(&place.clone().deref());
277-
self.gather_init(place, InitKind::Shallow);
277+
self.gather_init(place.as_place_ref(), InitKind::Shallow);
278278
} else {
279-
self.gather_init(place, InitKind::Deep);
279+
self.gather_init(place.as_place_ref(), InitKind::Deep);
280280
}
281281
self.gather_rvalue(rval);
282282
}
@@ -286,7 +286,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
286286
StatementKind::InlineAsm(ref asm) => {
287287
for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) {
288288
if !kind.is_indirect {
289-
self.gather_init(output, InitKind::Deep);
289+
self.gather_init(output.as_place_ref(), InitKind::Deep);
290290
}
291291
}
292292
for (_, input) in asm.inputs.iter() {
@@ -376,7 +376,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
376376
TerminatorKind::DropAndReplace { ref location, ref value, .. } => {
377377
self.create_move_path(location);
378378
self.gather_operand(value);
379-
self.gather_init(location, InitKind::Deep);
379+
self.gather_init(location.as_place_ref(), InitKind::Deep);
380380
}
381381
TerminatorKind::Call {
382382
ref func,
@@ -391,7 +391,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
391391
}
392392
if let Some((ref destination, _bb)) = *destination {
393393
self.create_move_path(destination);
394-
self.gather_init(destination, InitKind::NonPanicPathOnly);
394+
self.gather_init(destination.as_place_ref(), InitKind::NonPanicPathOnly);
395395
}
396396
}
397397
}
@@ -426,35 +426,35 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
426426
self.builder.data.loc_map[self.loc].push(move_out);
427427
}
428428

429-
fn gather_init(&mut self, place: &Place<'tcx>, kind: InitKind) {
429+
fn gather_init(&mut self, place: PlaceRef<'cx, 'tcx>, kind: InitKind) {
430430
debug!("gather_init({:?}, {:?})", self.loc, place);
431431

432432
let place = match place.projection {
433433
// Check if we are assigning into a field of a union, if so, lookup the place
434434
// of the union so it is marked as initialized again.
435435
Some(box Projection {
436-
base: ref proj_base,
436+
base: proj_base,
437437
elem: ProjectionElem::Field(_, _),
438438
}) => {
439439
if let ty::Adt(def, _) =
440-
Place::ty_from(&place.base, proj_base, self.builder.body, self.builder.tcx)
440+
Place::ty_from(place.base, proj_base, self.builder.body, self.builder.tcx)
441441
.ty
442442
.sty
443443
{
444444
if def.is_union() {
445-
Place { base: place.base.clone(), projection: proj_base.clone() }
445+
PlaceRef { base: place.base, projection: proj_base }
446446
} else {
447-
place.clone()
447+
place
448448
}
449449
} else {
450-
place.clone()
450+
place
451451
}
452452
}
453453

454-
_ => place.clone()
454+
_ => place
455455
};
456456

457-
if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place.as_place_ref()) {
457+
if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place) {
458458
let init = self.builder.data.inits.push(Init {
459459
location: InitLocation::Statement(self.loc),
460460
path,

0 commit comments

Comments
 (0)