*/
use mir::repr::*;
-use middle::const_eval::ConstVal;
-use middle::subst::{Subst, Substs};
-use middle::ty::{self, AdtDef, Ty};
-use rustc_front::hir;
+use ty::subst::{Subst, Substs};
+use ty::{self, AdtDef, Ty, TyCtxt};
+use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use hir;
#[derive(Copy, Clone, Debug)]
pub enum LvalueTy<'tcx> {
LvalueTy::Ty { ty: ty }
}
- pub fn to_ty(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
+ pub fn to_ty(&self, tcx: &TyCtxt<'tcx>) -> Ty<'tcx> {
match *self {
LvalueTy::Ty { ty } =>
ty,
}
pub fn projection_ty(self,
- tcx: &ty::ctxt<'tcx>,
+ tcx: &TyCtxt<'tcx>,
elem: &LvalueElem<'tcx>)
-> LvalueTy<'tcx>
{
variant_index: index }
}
_ => {
- tcx.sess.bug(&format!("cannot downcast non-enum type: `{:?}`", self))
+ bug!("cannot downcast non-enum type: `{:?}`", self)
}
},
ProjectionElem::Field(_, fty) => LvalueTy::Ty { ty: fty }
}
}
+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: &ty::ctxt<'tcx>,
+ tcx: &TyCtxt<'tcx>,
operand: &Operand<'tcx>)
-> Ty<'tcx>
{
}
pub fn binop_ty(&self,
- tcx: &ty::ctxt<'tcx>,
+ tcx: &TyCtxt<'tcx>,
op: BinOp,
lhs_ty: Ty<'tcx>,
rhs_ty: Ty<'tcx>)
}
pub fn lvalue_ty(&self,
- tcx: &ty::ctxt<'tcx>,
+ tcx: &TyCtxt<'tcx>,
lvalue: &Lvalue<'tcx>)
-> LvalueTy<'tcx>
{
}
pub fn rvalue_ty(&self,
- tcx: &ty::ctxt<'tcx>,
+ tcx: &TyCtxt<'tcx>,
rvalue: &Rvalue<'tcx>)
-> Option<Ty<'tcx>>
{
match *rvalue {
Rvalue::Use(ref operand) => Some(self.operand_ty(tcx, operand)),
Rvalue::Repeat(ref operand, ref count) => {
- if let ConstVal::Uint(u) = count.value {
- let op_ty = self.operand_ty(tcx, operand);
- Some(tcx.mk_array(op_ty, u as usize))
- } else {
- None
- }
+ let op_ty = self.operand_ty(tcx, operand);
+ let count = count.value.as_u64(tcx.sess.target.uint_type);
+ assert_eq!(count as usize as u64, count);
+ Some(tcx.mk_array(op_ty, count as usize))
}
Rvalue::Ref(reg, bk, ref lv) => {
let lv_ty = self.lvalue_ty(tcx, lv).to_ty(tcx);
}
}
Rvalue::Slice { .. } => None,
- Rvalue::InlineAsm(..) => None
+ Rvalue::InlineAsm { .. } => None
}
}
}