ReifyFnPointer => match self.operand_ty(operand).sty {
ty::TyFnDef(def_id, substs, _) => {
- let fn_ptr = self.memory.create_fn_ptr(def_id, substs);
+ let instance = resolve(self.tcx, def_id, substs);
+ let fn_ptr = self.memory.create_fn_alloc(instance);
self.write_value(Value::ByVal(PrimVal::Ptr(fn_ptr)), dest, dest_ty)?;
},
ref other => bug!("reify fn pointer on {:?}", other),
use std::collections::{btree_map, BTreeMap, HashMap, HashSet, VecDeque, BTreeSet};
use std::{fmt, iter, ptr, mem, io};
-use rustc::hir::def_id::DefId;
use rustc::ty;
-use rustc::ty::subst::Substs;
use rustc::ty::layout::{self, TargetDataLayout};
use error::{EvalError, EvalResult};
self.alloc_map.iter()
}
- pub fn create_fn_ptr(&mut self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Pointer {
- let instance = ty::Instance::new(def_id, substs);
- self.create_fn_alloc(instance)
- }
-
pub fn create_fn_alloc(&mut self, instance: ty::Instance<'tcx>) -> Pointer {
if let Some(&alloc_id) = self.function_alloc_cache.get(&instance) {
return Pointer::new(alloc_id, 0);
ty::TyFnPtr(sig) => {
let fn_ptr = self.eval_operand_to_primval(func)?.to_ptr()?;
let instance = self.memory.get_fn(fn_ptr.alloc_id)?;
- match instance.def.def_ty(self.tcx).sty {
+ let instance_ty = instance.def.def_ty(self.tcx);
+ let instance_ty = self.monomorphize(instance_ty, instance.substs);
+ match instance_ty.sty {
ty::TyFnDef(_, _, real_sig) => {
let sig = self.erase_lifetimes(&sig);
let real_sig = self.erase_lifetimes(&real_sig);