1
Fork 0

Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino

Use PlaceRef abstractions more often

Associated issue: https://github.com/rust-lang/rust/issues/80647

r? `@spastorino`
This commit is contained in:
bors 2023-06-27 00:34:49 +00:00
commit b9ad9b78a2
10 changed files with 40 additions and 93 deletions

View file

@ -677,21 +677,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// check that we just did stays valid. Since we can't assign to
// unsized values, we only need to ensure that none of the
// pointers in the base place are modified.
for (idx, elem) in base_place.projection.iter().enumerate().rev() {
for (base_place, elem) in base_place.iter_projections().rev() {
match elem {
ProjectionElem::Deref => {
let fake_borrow_deref_ty = Place::ty_from(
base_place.local,
&base_place.projection[..idx],
&self.local_decls,
tcx,
)
.ty;
let fake_borrow_deref_ty = base_place.ty(&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(fake_borrow_ty, expr_span));
let projection = tcx.mk_place_elems(&base_place.projection[..idx]);
let projection = tcx.mk_place_elems(&base_place.projection);
self.cfg.push_assign(
block,
source_info,
@ -705,12 +699,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fake_borrow_temps.push(fake_borrow_temp);
}
ProjectionElem::Index(_) => {
let index_ty = Place::ty_from(
base_place.local,
&base_place.projection[..idx],
&self.local_decls,
tcx,
);
let index_ty = base_place.ty(&self.local_decls, tcx);
match index_ty.ty.kind() {
// The previous index expression has already
// done any index expressions needed here.