add function to iterate through all sub-places, and add PlaceRef::ty
This commit is contained in:
parent
af309cc2d9
commit
df1c55a474
@ -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<'_> {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user