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)]
}
}
+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>,
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);