Avoid math and use patterns to grab projection base
This commit is contained in:
parent
232a4a2881
commit
07a706ecf5
5 changed files with 23 additions and 34 deletions
|
@ -1520,10 +1520,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
[] => {
|
[] => {
|
||||||
StorageDeadOrDrop::LocalStorageDead
|
StorageDeadOrDrop::LocalStorageDead
|
||||||
}
|
}
|
||||||
[.., elem] => {
|
[base @ .., elem] => {
|
||||||
// FIXME(spastorino) revisit when we get rid of Box
|
|
||||||
let base = &place.projection[..place.projection.len() - 1];
|
|
||||||
|
|
||||||
// FIXME(spastorino) make this iterate
|
// FIXME(spastorino) make this iterate
|
||||||
let base_access = self.classify_drop_access_kind(PlaceRef {
|
let base_access = self.classify_drop_access_kind(PlaceRef {
|
||||||
base: place.base,
|
base: place.base,
|
||||||
|
|
|
@ -2324,14 +2324,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
let mut place_projection = place_ref.projection;
|
let mut place_projection = place_ref.projection;
|
||||||
let mut by_ref = false;
|
let mut by_ref = false;
|
||||||
|
|
||||||
if let [.., ProjectionElem::Deref] = place_projection {
|
if let [proj_base @ .., ProjectionElem::Deref] = place_projection {
|
||||||
place_projection = &place_projection[..place_projection.len() - 1];
|
place_projection = proj_base;
|
||||||
by_ref = true;
|
by_ref = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
match place_projection {
|
match place_projection {
|
||||||
[.., ProjectionElem::Field(field, _ty)] => {
|
[base @ .., ProjectionElem::Field(field, _ty)] => {
|
||||||
let base = &place_projection[..place_projection.len() - 1];
|
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let base_ty = Place::ty_from(place_ref.base, base, self.body, tcx).ty;
|
let base_ty = Place::ty_from(place_ref.base, base, self.body, tcx).ty;
|
||||||
|
|
||||||
|
|
|
@ -82,11 +82,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
PlaceRef {
|
PlaceRef {
|
||||||
base: _,
|
base: _,
|
||||||
projection: [.., ProjectionElem::Deref],
|
projection: [base @ .., ProjectionElem::Deref],
|
||||||
} => {
|
} => {
|
||||||
// FIXME(spastorino) once released use box [base @ .., ProjectionElem::Deref]
|
|
||||||
let base = &the_place_err.projection[..the_place_err.projection.len() - 1];
|
|
||||||
|
|
||||||
if the_place_err.base == &PlaceBase::Local(Local::new(1)) &&
|
if the_place_err.base == &PlaceBase::Local(Local::new(1)) &&
|
||||||
base.is_empty() &&
|
base.is_empty() &&
|
||||||
!self.upvars.is_empty() {
|
!self.upvars.is_empty() {
|
||||||
|
@ -243,14 +240,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
// after the field access).
|
// after the field access).
|
||||||
PlaceRef {
|
PlaceRef {
|
||||||
base,
|
base,
|
||||||
projection: [..,
|
projection: [base_proj @ ..,
|
||||||
ProjectionElem::Deref,
|
ProjectionElem::Deref,
|
||||||
ProjectionElem::Field(field, _),
|
ProjectionElem::Field(field, _),
|
||||||
ProjectionElem::Deref,
|
ProjectionElem::Deref,
|
||||||
],
|
],
|
||||||
} => {
|
} => {
|
||||||
let base_proj = &the_place_err.projection[..the_place_err.projection.len() - 3];
|
|
||||||
|
|
||||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||||
|
|
||||||
if let Some((span, message)) = annotate_struct_field(
|
if let Some((span, message)) = annotate_struct_field(
|
||||||
|
|
|
@ -514,20 +514,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
Place {
|
Place {
|
||||||
ref base,
|
ref base,
|
||||||
projection: box [.., ProjectionElem::Field(upvar_index, _)],
|
projection: box [ref base_proj @ .., ProjectionElem::Field(upvar_index, _)],
|
||||||
}
|
}
|
||||||
| Place {
|
| Place {
|
||||||
ref base,
|
ref base,
|
||||||
projection: box [.., ProjectionElem::Field(upvar_index, _), ProjectionElem::Deref],
|
projection: box [
|
||||||
|
ref base_proj @ ..,
|
||||||
|
ProjectionElem::Field(upvar_index, _),
|
||||||
|
ProjectionElem::Deref
|
||||||
|
],
|
||||||
} => {
|
} => {
|
||||||
let base_proj = if let ProjectionElem::Deref =
|
|
||||||
arg_place.projection[arg_place.projection.len() - 1]
|
|
||||||
{
|
|
||||||
&arg_place.projection[..arg_place.projection.len() - 2]
|
|
||||||
} else {
|
|
||||||
&arg_place.projection[..arg_place.projection.len() - 1]
|
|
||||||
};
|
|
||||||
|
|
||||||
let place = PlaceRef {
|
let place = PlaceRef {
|
||||||
base,
|
base,
|
||||||
projection: base_proj,
|
projection: base_proj,
|
||||||
|
|
|
@ -45,16 +45,18 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
|
||||||
ref mut base,
|
ref mut base,
|
||||||
projection: ref mut projection @ box [.., _],
|
projection: ref mut projection @ box [.., _],
|
||||||
}) => {
|
}) => {
|
||||||
let [proj_l @ .., proj_r] = projection;
|
if let box [proj_l @ .., proj_r] = projection {
|
||||||
|
let place = Place {
|
||||||
|
// Replace with dummy
|
||||||
|
base: mem::replace(base, PlaceBase::Local(Local::new(0))),
|
||||||
|
projection: proj_l.to_vec().into_boxed_slice(),
|
||||||
|
};
|
||||||
|
*projection = vec![proj_r.clone()].into_boxed_slice();
|
||||||
|
|
||||||
let place = Place {
|
place
|
||||||
// Replace with dummy
|
} else {
|
||||||
base: mem::replace(base, PlaceBase::Local(Local::new(0))),
|
unreachable!();
|
||||||
projection: proj_l.to_vec().into_boxed_slice(),
|
}
|
||||||
};
|
|
||||||
*projection = proj_r.to_vec().into_boxed_slice();
|
|
||||||
|
|
||||||
place
|
|
||||||
}
|
}
|
||||||
_ => bug!("Detected `&*` but didn't find `&*`!"),
|
_ => bug!("Detected `&*` but didn't find `&*`!"),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue