Skip to content

Commit d77653e

Browse files
committed
Avoid cloning Place in calculate_fake_borrows
1 parent 2ffd3c6 commit d77653e

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ newtype_index! {
18261826
}
18271827
}
18281828

1829-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1829+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
18301830
pub struct PlaceRef<'a, 'tcx> {
18311831
pub base: &'a PlaceBase<'tcx>,
18321832
pub projection: &'a Option<Box<Projection<'tcx>>>,

src/librustc_mir/build/matches/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12801280
&mut self,
12811281
fake_borrows: &'b FxHashSet<Place<'tcx>>,
12821282
temp_span: Span,
1283-
) -> Vec<(Place<'tcx>, Local)> {
1283+
) -> Vec<(PlaceRef<'b, 'tcx>, Local)> {
12841284
let tcx = self.hir.tcx();
12851285

12861286
debug!("add_fake_borrows fake_borrows = {:?}", fake_borrows);
@@ -1296,15 +1296,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12961296
// Insert a shallow borrow after a deref. For other
12971297
// projections the borrow of prefix_cursor will
12981298
// conflict with any mutation of base.
1299-
all_fake_borrows.push(Place {
1300-
base: place.base.clone(),
1301-
projection: base.clone(),
1299+
all_fake_borrows.push(PlaceRef {
1300+
base: &place.base,
1301+
projection: base,
13021302
});
13031303
}
13041304
prefix_cursor = base;
13051305
}
13061306

1307-
all_fake_borrows.push(place.clone());
1307+
all_fake_borrows.push(place.as_place_ref());
13081308
}
13091309

13101310
// Deduplicate and ensure a deterministic order.
@@ -1314,7 +1314,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13141314
debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);
13151315

13161316
all_fake_borrows.into_iter().map(|matched_place| {
1317-
let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty;
1317+
let fake_borrow_deref_ty = Place::ty_from(
1318+
matched_place.base,
1319+
matched_place.projection,
1320+
&self.local_decls,
1321+
tcx,
1322+
)
1323+
.ty;
13181324
let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty);
13191325
let fake_borrow_temp = self.local_decls.push(
13201326
LocalDecl::new_temp(fake_borrow_ty, temp_span)
@@ -1345,7 +1351,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13451351
&mut self,
13461352
candidate: Candidate<'pat, 'tcx>,
13471353
guard: Option<Guard<'tcx>>,
1348-
fake_borrows: &Vec<(Place<'tcx>, Local)>,
1354+
fake_borrows: &Vec<(PlaceRef<'_, 'tcx>, Local)>,
13491355
scrutinee_span: Span,
13501356
region_scope: region::Scope,
13511357
) -> BasicBlock {
@@ -1480,7 +1486,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14801486
let borrow = Rvalue::Ref(
14811487
re_erased,
14821488
BorrowKind::Shallow,
1483-
place.clone(),
1489+
Place {
1490+
base: place.base.clone(),
1491+
projection: place.projection.clone(),
1492+
},
14841493
);
14851494
self.cfg.push_assign(
14861495
block,

0 commit comments

Comments
 (0)