diff options
| author | Ralf Jung <post@ralfj.de> | 2020-11-20 11:50:15 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-11-21 12:48:56 +0100 |
| commit | df1c55a47434b2d79dea43673a3a97b9e955ce82 (patch) | |
| tree | ed7ce71e79f7eda114837e1da505428def333d2d | |
| parent | af309cc2d93ce1e8e57cedffbfc35f9df040376a (diff) | |
| download | rust-df1c55a47434b2d79dea43673a3a97b9e955ce82.tar.gz rust-df1c55a47434b2d79dea43673a3a97b9e955ce82.zip | |
add function to iterate through all sub-places, and add PlaceRef::ty
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/tcx.rs | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 9289d4708de..4a7d4dab507 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1741,6 +1741,15 @@ impl<'tcx> Place<'tcx> { pub fn as_ref(&self) -> PlaceRef<'tcx> { PlaceRef { local: self.local, projection: &self.projection } } + + /// 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. + 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 From<Local> for Place<'_> { diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index f0bfdae261c..1b2c1076a68 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -136,6 +136,15 @@ impl<'tcx> Place<'tcx> { } } +impl<'tcx> PlaceRef<'tcx> { + pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> + where + D: HasLocalDecls<'tcx>, + { + Place::ty_from(self.local, &self.projection, local_decls, tcx) + } +} + pub enum RvalueInitializationState { Shallow, Deep, |
