mir: Monomorphize LvalueTy's of projections.

This commit is contained in:
Eduard Burtescu 2016-03-08 14:11:45 +02:00
parent f9c06abc21
commit 56417b3732
2 changed files with 25 additions and 0 deletions

View 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 @@ impl<'tcx> LvalueTy<'tcx> {
}
}
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>,

View File

@ -114,6 +114,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
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);