Skip to content

Commit aafddd2

Browse files
Rollup merge of #98388 - rosehuds:master, r=davidtwco
implement `iter_projections` function on `PlaceRef` this makes the api more flexible. the original function now calls the PlaceRef version to avoid duplicating the code.
2 parents 667a546 + 53481a5 commit aafddd2

File tree

1 file changed

+18
-4
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+18
-4
lines changed

compiler/rustc_middle/src/mir/mod.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
21452145
pub fn iter_projections(
21462146
self,
21472147
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
2148-
self.projection.iter().enumerate().map(move |(i, proj)| {
2149-
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
2150-
(base, proj)
2151-
})
2148+
self.as_ref().iter_projections()
21522149
}
21532150

21542151
/// Generates a new place by appending `more_projections` to the existing ones
@@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
22082205
None
22092206
}
22102207
}
2208+
2209+
/// Iterate over the projections in evaluation order, i.e., the first element is the base with
2210+
/// its projection and then subsequently more projections are added.
2211+
/// As a concrete example, given the place a.b.c, this would yield:
2212+
/// - (a, .b)
2213+
/// - (a.b, .c)
2214+
///
2215+
/// Given a place without projections, the iterator is empty.
2216+
#[inline]
2217+
pub fn iter_projections(
2218+
self,
2219+
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
2220+
self.projection.iter().enumerate().map(move |(i, proj)| {
2221+
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
2222+
(base, *proj)
2223+
})
2224+
}
22112225
}
22122226

22132227
impl Debug for Place<'_> {

0 commit comments

Comments
 (0)