]> git.lizzy.rs Git - rust.git/commitdiff
Fix substs in nested generic function calls.
authorScott Olson <scott@solson.me>
Tue, 15 Mar 2016 04:26:39 +0000 (22:26 -0600)
committerScott Olson <scott@solson.me>
Tue, 15 Mar 2016 04:26:39 +0000 (22:26 -0600)
src/interpreter.rs

index 2d81b1b265fd783a6045fa72d2b027b75aea46c8..14e4323a5f195dff1d2581e21299339a119bd072 100644 (file)
@@ -225,6 +225,8 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> EvalResult<
                 match func_ty.sty {
                     ty::TyFnDef(def_id, substs, _) => {
                         let mir = self.load_mir(def_id);
+                        let substs = self.tcx.mk_substs(
+                            substs.subst(self.tcx, self.current_substs()));
                         self.substs_stack.push(substs);
                         try!(self.push_stack_frame(mir, args, return_ptr));
                         TerminatorTarget::Call
@@ -436,11 +438,8 @@ fn make_variant_repr(&self, v: ty::VariantDef<'tcx>, substs: &'tcx Substs<'tcx>)
 
     // TODO(tsion): Cache these outputs.
     fn ty_to_repr(&self, ty: ty::Ty<'tcx>) -> Repr {
-        use syntax::ast::IntTy;
-        let substs = self.substs_stack.last().map(|&s| s)
-            .unwrap_or_else(|| self.tcx.mk_substs(Substs::empty()));
-
-        match ty.subst(self.tcx, substs).sty {
+        use syntax::ast::{IntTy, UintTy};
+        match ty.subst(self.tcx, self.current_substs()).sty {
             ty::TyBool => Repr::Bool,
 
             ty::TyInt(IntTy::Is) => unimplemented!(),
@@ -498,6 +497,10 @@ fn current_frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
         self.stack.last_mut().expect("no call frames exist")
     }
 
+    fn current_substs(&self) -> &'tcx Substs<'tcx> {
+        self.substs_stack.last().cloned().unwrap_or_else(|| self.tcx.mk_substs(Substs::empty()))
+    }
+
     fn load_mir(&self, def_id: DefId) -> CachedMir<'a, 'tcx> {
         match self.tcx.map.as_local_node_id(def_id) {
             Some(node_id) => CachedMir::Ref(self.mir_map.map.get(&node_id).unwrap()),
@@ -560,6 +563,7 @@ fn print_allocation_tree(memory: &Memory, alloc_id: memory::AllocId) {
                 if let Some(ret) = return_ptr {
                     println!("Result:");
                     print_allocation_tree(&miri.memory, ret.alloc_id);
+                    println!("");
                 }
             }
         }