Skip to content

Commit df1c55a

Browse files
committed
add function to iterate through all sub-places, and add PlaceRef::ty
1 parent af309cc commit df1c55a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

compiler/rustc_middle/src/mir/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,15 @@ impl<'tcx> Place<'tcx> {
17411741
pub fn as_ref(&self) -> PlaceRef<'tcx> {
17421742
PlaceRef { local: self.local, projection: &self.projection }
17431743
}
1744+
1745+
/// Iterate over the projections in evaluation order, i.e., the first element is the base with
1746+
/// its projection and then subsequently more projections are added.
1747+
pub fn iter_projections(self) -> impl Iterator<Item=(PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
1748+
self.projection.iter().enumerate().map(move |(i, proj)| {
1749+
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
1750+
(base, proj)
1751+
})
1752+
}
17441753
}
17451754

17461755
impl From<Local> for Place<'_> {

compiler/rustc_middle/src/mir/tcx.rs

+9
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ impl<'tcx> Place<'tcx> {
136136
}
137137
}
138138

139+
impl<'tcx> PlaceRef<'tcx> {
140+
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
141+
where
142+
D: HasLocalDecls<'tcx>,
143+
{
144+
Place::ty_from(self.local, &self.projection, local_decls, tcx)
145+
}
146+
}
147+
139148
pub enum RvalueInitializationState {
140149
Shallow,
141150
Deep,

0 commit comments

Comments
 (0)