add function to iterate through all sub-places, and add PlaceRef::ty

This commit is contained in:
Ralf Jung 2020-11-20 11:50:15 +01:00
parent af309cc2d9
commit df1c55a474
2 changed files with 18 additions and 0 deletions

View File

@ -1741,6 +1741,15 @@ impl<'tcx> Place<'tcx> {
pub fn as_ref(&self) -> PlaceRef<'tcx> {
PlaceRef { local: self.local, projection: &self.projection }
}
/// Iterate over the projections in evaluation order, i.e., the first element is the base with
/// its projection and then subsequently more projections are added.
pub fn iter_projections(self) -> impl Iterator<Item=(PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
self.projection.iter().enumerate().map(move |(i, proj)| {
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
(base, proj)
})
}
}
impl From<Local> for Place<'_> {

View File

@ -136,6 +136,15 @@ impl<'tcx> Place<'tcx> {
}
}
impl<'tcx> PlaceRef<'tcx> {
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
where
D: HasLocalDecls<'tcx>,
{
Place::ty_from(self.local, &self.projection, local_decls, tcx)
}
}
pub enum RvalueInitializationState {
Shallow,
Deep,