]> git.lizzy.rs Git - rust.git/commitdiff
Normalize associated types when monomorphizing.
authorScott Olson <scott@solson.me>
Fri, 18 Mar 2016 17:52:13 +0000 (11:52 -0600)
committerScott Olson <scott@solson.me>
Fri, 18 Mar 2016 17:52:13 +0000 (11:52 -0600)
src/interpreter.rs

index 3e1444ad51640646264c1d3f4bda7f53f379644f..c8259063f4209ae97a104e779b0981ce22200942 100644 (file)
@@ -1,6 +1,7 @@
 use arena::TypedArena;
 use rustc::middle::const_eval;
 use rustc::middle::def_id::DefId;
+use rustc::middle::infer;
 use rustc::middle::subst::{self, Subst, Substs};
 use rustc::middle::traits;
 use rustc::middle::ty::{self, TyCtxt};
@@ -12,6 +13,7 @@
 use std::iter;
 use std::ops::Deref;
 use std::rc::Rc;
+use syntax::ast;
 use syntax::codemap::DUMMY_SP;
 
 use error::EvalResult;
@@ -485,9 +487,8 @@ fn pointee_type<'tcx>(ptr_ty: ty::Ty<'tcx>) -> Option<ty::Ty<'tcx>> {
     }
 
     fn operand_ty(&self, operand: &mir::Operand<'tcx>) -> ty::Ty<'tcx> {
-        self.current_frame().mir
-            .operand_ty(self.tcx, operand)
-            .subst(self.tcx, self.current_substs())
+        let ty = self.current_frame().mir.operand_ty(self.tcx, operand);
+        self.monomorphize(ty)
     }
 
     fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<Pointer> {
@@ -594,12 +595,17 @@ fn const_to_ptr(&mut self, const_val: &const_eval::ConstVal) -> EvalResult<Point
         }
     }
 
+    fn monomorphize(&self, ty: ty::Ty<'tcx>) -> ty::Ty<'tcx> {
+        let substituted = ty.subst(self.tcx, self.current_substs());
+        infer::normalize_associated_type(self.tcx, &substituted)
+    }
+
     fn ty_size(&self, ty: ty::Ty<'tcx>) -> usize {
         self.ty_to_repr(ty).size()
     }
 
     fn ty_to_repr(&self, ty: ty::Ty<'tcx>) -> &'arena Repr {
-        let ty = ty.subst(self.tcx, self.current_substs());
+        let ty = self.monomorphize(ty);
 
         if let Some(repr) = self.repr_cache.borrow().get(ty) {
             return repr;
@@ -724,9 +730,6 @@ fn load_mir(&self, def_id: DefId) -> CachedMir<'a, 'tcx> {
     }
 
     fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> {
-        use rustc::middle::infer;
-        use syntax::ast;
-
         // Do the initial selection for the obligation. This yields the shallow result we are
         // looking for -- that is, what specific impl.
         let infcx = infer::normalizing_infer_ctxt(self.tcx, &self.tcx.tables);