File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
compiler/rustc_middle/src/mir Expand file tree Collapse file tree 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> {
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
22132227impl Debug for Place < ' _ > {
You can’t perform that action at this time.
0 commit comments