diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-19 17:34:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-19 17:34:39 +0200 |
| commit | bf6c505c23a1026282cc0518743c9cd6e727c2aa (patch) | |
| tree | 340f2e3775fb368108e2fe31ba8b24c9aa521111 | |
| parent | d88b7b213677ea3dde73e08a39104f6850f3a074 (diff) | |
| parent | f4737d5607eabbfc07440b0ce64b852395948a68 (diff) | |
| download | rust-bf6c505c23a1026282cc0518743c9cd6e727c2aa.tar.gz rust-bf6c505c23a1026282cc0518743c9cd6e727c2aa.zip | |
Rollup merge of #61940 - spastorino:place-ty-iterate, r=oli-obk
Make Place::ty iterate r? @oli-obk Related to Place 2.0
| -rw-r--r-- | src/librustc/mir/tcx.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index afabcdfadd0..2079a2a34e7 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -122,13 +122,25 @@ impl<'tcx> Place<'tcx> { where D: HasLocalDecls<'tcx>, { - match *self { - Place::Base(PlaceBase::Local(index)) => - PlaceTy::from_ty(local_decls.local_decls()[index].ty), - Place::Base(PlaceBase::Static(ref data)) => - PlaceTy::from_ty(data.ty), - Place::Projection(ref proj) => - proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem), + self.iterate(|place_base, place_projections| { + let mut place_ty = place_base.ty(local_decls); + + for proj in place_projections { + place_ty = place_ty.projection_ty(tcx, &proj.elem); + } + + place_ty + }) + } +} + +impl<'tcx> PlaceBase<'tcx> { + pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx> + where D: HasLocalDecls<'tcx> + { + match self { + PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty), + PlaceBase::Static(data) => PlaceTy::from_ty(data.ty), } } } |
