use super::MirBorrowckCtxt;
-use rustc::hir;
+use rustc::mir::{Place, PlaceRef, ProjectionElem, ReadOnlyBodyAndCache};
use rustc::ty::{self, TyCtxt};
-use rustc::mir::{Place, PlaceBase, PlaceRef, ProjectionElem, ReadOnlyBodyAndCache};
+use rustc_hir as hir;
pub trait IsPrefixOf<'cx, 'tcx> {
fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool;
impl<'cx, 'tcx> IsPrefixOf<'cx, 'tcx> for PlaceRef<'cx, 'tcx> {
fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool {
- self.base == other.base
+ self.local == other.local
&& self.projection.len() <= other.projection.len()
&& self.projection == &other.projection[..self.projection.len()]
}
place_ref: PlaceRef<'cx, 'tcx>,
kind: PrefixSet,
) -> Prefixes<'cx, 'tcx> {
- Prefixes {
- next: Some(place_ref),
- kind,
- body: self.body,
- tcx: self.infcx.tcx,
- }
+ Prefixes { next: Some(place_ref), kind, body: self.body, tcx: self.infcx.tcx }
}
}
'cursor: loop {
match &cursor {
- PlaceRef {
- base: PlaceBase::Local(_),
- projection: [],
- }
- | // search yielded this leaf
- PlaceRef {
- base: PlaceBase::Static(_),
- projection: [],
- } => {
+ PlaceRef { local: _, projection: [] } => {
self.next = None;
return Some(cursor);
}
- PlaceRef {
- base: _,
- projection: [proj_base @ .., elem],
- } => {
+ PlaceRef { local: _, projection: [proj_base @ .., elem] } => {
match elem {
ProjectionElem::Field(_ /*field*/, _ /*ty*/) => {
// FIXME: add union handling
- self.next = Some(PlaceRef {
- base: cursor.base,
- projection: proj_base,
- });
+ self.next =
+ Some(PlaceRef { local: cursor.local, projection: proj_base });
return Some(cursor);
}
- ProjectionElem::Downcast(..) |
- ProjectionElem::Subslice { .. } |
- ProjectionElem::ConstantIndex { .. } |
- ProjectionElem::Index(_) => {
- cursor = PlaceRef {
- base: cursor.base,
- projection: proj_base,
- };
+ ProjectionElem::Downcast(..)
+ | ProjectionElem::Subslice { .. }
+ | ProjectionElem::ConstantIndex { .. }
+ | ProjectionElem::Index(_) => {
+ cursor = PlaceRef { local: cursor.local, projection: proj_base };
continue 'cursor;
}
ProjectionElem::Deref => {
PrefixSet::All => {
// All prefixes: just blindly enqueue the base
// of the projection.
- self.next = Some(PlaceRef {
- base: cursor.base,
- projection: proj_base,
- });
+ self.next =
+ Some(PlaceRef { local: cursor.local, projection: proj_base });
return Some(cursor);
}
PrefixSet::Supporting => {
// derefs, except we stop at the deref of a shared
// reference.
- let ty = Place::ty_from(cursor.base, proj_base, *self.body, self.tcx).ty;
+ let ty = Place::ty_from(cursor.local, proj_base, *self.body, self.tcx).ty;
match ty.kind {
- ty::RawPtr(_) |
- ty::Ref(
- _, /*rgn*/
- _, /*ty*/
- hir::Mutability::Not
- ) => {
+ ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
// don't continue traversing over derefs of raw pointers or shared
// borrows.
self.next = None;
return Some(cursor);
}
- ty::Ref(
- _, /*rgn*/
- _, /*ty*/
- hir::Mutability::Mut,
- ) => {
- self.next = Some(PlaceRef {
- base: cursor.base,
- projection: proj_base,
- });
+ ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Mut) => {
+ self.next =
+ Some(PlaceRef { local: cursor.local, projection: proj_base });
return Some(cursor);
}
ty::Adt(..) if ty.is_box() => {
- self.next = Some(PlaceRef {
- base: cursor.base,
- projection: proj_base,
- });
+ self.next =
+ Some(PlaceRef { local: cursor.local, projection: proj_base });
return Some(cursor);
}