From 9e1bb9841ee885be82fce24752a8e3de17ab485b Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Mon, 14 Mar 2016 22:26:39 -0600 Subject: [PATCH] Fix substs in nested generic function calls. --- src/interpreter.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 2d81b1b265fd..14e4323a5f19 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -225,6 +225,8 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> { 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 @@ impl<'a, 'tcx: 'a> Interpreter<'a, '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 @@ impl<'a, 'tcx: 'a> Interpreter<'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 @@ pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) if let Some(ret) = return_ptr { println!("Result:"); print_allocation_tree(&miri.memory, ret.alloc_id); + println!(""); } } }