]> git.lizzy.rs Git - rust.git/commitdiff
mir: Monomorphize LvalueTy's of projections.
authorEduard Burtescu <edy.burt@gmail.com>
Tue, 8 Mar 2016 12:11:45 +0000 (14:11 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Thu, 17 Mar 2016 19:51:53 +0000 (21:51 +0200)
src/librustc/mir/tcx.rs
src/librustc_trans/trans/mir/lvalue.rs

index b6b2694a7cbe1c2d3d53f4e8f148930a683794c3..d7848e60e4ecedeca8d9086ade7ac1a04ede2154 100644 (file)
@@ -16,6 +16,7 @@
 use mir::repr::*;
 use middle::subst::{Subst, Substs};
 use middle::ty::{self, AdtDef, Ty, TyCtxt};
+use middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 use rustc_front::hir;
 
 #[derive(Copy, Clone, Debug)]
@@ -77,6 +78,29 @@ pub fn projection_ty(self,
     }
 }
 
+impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
+    fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
+        match *self {
+            LvalueTy::Ty { ty } => LvalueTy::Ty { ty: ty.fold_with(folder) },
+            LvalueTy::Downcast { adt_def, substs, variant_index } => {
+                let substs = substs.fold_with(folder);
+                LvalueTy::Downcast {
+                    adt_def: adt_def,
+                    substs: folder.tcx().mk_substs(substs),
+                    variant_index: variant_index
+                }
+            }
+        }
+    }
+
+    fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
+        match *self {
+            LvalueTy::Ty { ty } => ty.visit_with(visitor),
+            LvalueTy::Downcast { substs, .. } => substs.visit_with(visitor)
+        }
+    }
+}
+
 impl<'tcx> Mir<'tcx> {
     pub fn operand_ty(&self,
                       tcx: &TyCtxt<'tcx>,
index 796a7c551f3999baefa62cb7a9a4128f184e0b97..66cbe677bb33aa15032f0d36c59955d53ab7ee52 100644 (file)
@@ -114,6 +114,7 @@ pub fn trans_lvalue(&mut self,
             mir::Lvalue::Projection(ref projection) => {
                 let tr_base = self.trans_lvalue(bcx, &projection.base);
                 let projected_ty = tr_base.ty.projection_ty(tcx, &projection.elem);
+                let projected_ty = bcx.monomorphize(&projected_ty);
                 let (llprojected, llextra) = match projection.elem {
                     mir::ProjectionElem::Deref => {
                         let base_ty = tr_base.ty.to_ty(tcx);