Avoid cloning Place in calculate_fake_borrows
This commit is contained in:
parent
2ffd3c64f9
commit
d77653e88b
@ -1826,7 +1826,7 @@ pub struct Field {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct PlaceRef<'a, 'tcx> {
|
||||
pub base: &'a PlaceBase<'tcx>,
|
||||
pub projection: &'a Option<Box<Projection<'tcx>>>,
|
||||
|
@ -1280,7 +1280,7 @@ fn calculate_fake_borrows<'b>(
|
||||
&mut self,
|
||||
fake_borrows: &'b FxHashSet<Place<'tcx>>,
|
||||
temp_span: Span,
|
||||
) -> Vec<(Place<'tcx>, Local)> {
|
||||
) -> Vec<(PlaceRef<'b, 'tcx>, Local)> {
|
||||
let tcx = self.hir.tcx();
|
||||
|
||||
debug!("add_fake_borrows fake_borrows = {:?}", fake_borrows);
|
||||
@ -1296,15 +1296,15 @@ fn calculate_fake_borrows<'b>(
|
||||
// Insert a shallow borrow after a deref. For other
|
||||
// projections the borrow of prefix_cursor will
|
||||
// conflict with any mutation of base.
|
||||
all_fake_borrows.push(Place {
|
||||
base: place.base.clone(),
|
||||
projection: base.clone(),
|
||||
all_fake_borrows.push(PlaceRef {
|
||||
base: &place.base,
|
||||
projection: base,
|
||||
});
|
||||
}
|
||||
prefix_cursor = base;
|
||||
}
|
||||
|
||||
all_fake_borrows.push(place.clone());
|
||||
all_fake_borrows.push(place.as_place_ref());
|
||||
}
|
||||
|
||||
// Deduplicate and ensure a deterministic order.
|
||||
@ -1314,7 +1314,13 @@ fn calculate_fake_borrows<'b>(
|
||||
debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);
|
||||
|
||||
all_fake_borrows.into_iter().map(|matched_place| {
|
||||
let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty;
|
||||
let fake_borrow_deref_ty = Place::ty_from(
|
||||
matched_place.base,
|
||||
matched_place.projection,
|
||||
&self.local_decls,
|
||||
tcx,
|
||||
)
|
||||
.ty;
|
||||
let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty);
|
||||
let fake_borrow_temp = self.local_decls.push(
|
||||
LocalDecl::new_temp(fake_borrow_ty, temp_span)
|
||||
@ -1345,7 +1351,7 @@ fn bind_and_guard_matched_candidate<'pat>(
|
||||
&mut self,
|
||||
candidate: Candidate<'pat, 'tcx>,
|
||||
guard: Option<Guard<'tcx>>,
|
||||
fake_borrows: &Vec<(Place<'tcx>, Local)>,
|
||||
fake_borrows: &Vec<(PlaceRef<'_, 'tcx>, Local)>,
|
||||
scrutinee_span: Span,
|
||||
region_scope: region::Scope,
|
||||
) -> BasicBlock {
|
||||
@ -1480,7 +1486,10 @@ fn bind_and_guard_matched_candidate<'pat>(
|
||||
let borrow = Rvalue::Ref(
|
||||
re_erased,
|
||||
BorrowKind::Shallow,
|
||||
place.clone(),
|
||||
Place {
|
||||
base: place.base.clone(),
|
||||
projection: place.projection.clone(),
|
||||
},
|
||||
);
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
|
Loading…
Reference in New Issue
Block a user