File tree 1 file changed +18
-4
lines changed
compiler/rustc_middle/src/mir
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
2145
2145
pub fn iter_projections (
2146
2146
self ,
2147
2147
) -> 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 ( )
2152
2149
}
2153
2150
2154
2151
/// Generates a new place by appending `more_projections` to the existing ones
@@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
2208
2205
None
2209
2206
}
2210
2207
}
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
+ }
2211
2225
}
2212
2226
2213
2227
impl Debug for Place < ' _ > {
You can’t perform that action at this time.
0 commit comments