Skip to content

Commit

Permalink
Rollup merge of #98388 - rosehuds:master, r=davidtwco
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compiler-errors committed Jun 23, 2022
2 parents 667a546 + 53481a5 commit aafddd2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
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)
})
self.as_ref().iter_projections()
}

/// Generates a new place by appending `more_projections` to the existing ones
Expand Down Expand Up @@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
None
}
}

/// 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.
/// As a concrete example, given the place a.b.c, this would yield:
/// - (a, .b)
/// - (a.b, .c)
///
/// Given a place without projections, the iterator is empty.
#[inline]
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 Debug for Place<'_> {
Expand Down

0 comments on commit aafddd2

Please sign in to comment.