File tree 2 files changed +18
-0
lines changed
compiler/rustc_middle/src/mir
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1741,6 +1741,15 @@ impl<'tcx> Place<'tcx> {
1741
1741
pub fn as_ref ( & self ) -> PlaceRef < ' tcx > {
1742
1742
PlaceRef { local : self . local , projection : & self . projection }
1743
1743
}
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
+ }
1744
1753
}
1745
1754
1746
1755
impl From < Local > for Place < ' _ > {
Original file line number Diff line number Diff line change @@ -136,6 +136,15 @@ impl<'tcx> Place<'tcx> {
136
136
}
137
137
}
138
138
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
+
139
148
pub enum RvalueInitializationState {
140
149
Shallow ,
141
150
Deep ,
You can’t perform that action at this time.
0 commit comments