let ref_ty = monomorphize::apply_param_substs(tcx,
param_substs,
&ref_ty);
- let llptrty = type_of::type_of_fn_from_ty(ccx, ref_ty).ptr_to();
+ let llptrty = type_of::type_of(ccx, ref_ty);
if llptrty != common::val_ty(val) {
let val = consts::ptrcast(val, llptrty);
return Datum::new(val, ref_ty, Rvalue::new(ByValue));
// This can occur on either a crate-local or crate-external
// reference. It also occurs when testing libcore and in some
// other weird situations. Annoying.
- let llty = type_of::type_of_fn_from_ty(ccx, fn_type);
- let llptrty = llty.ptr_to();
+ let llptrty = type_of::type_of(ccx, fn_type);
if common::val_ty(val) != llptrty {
debug!("trans_fn_ref_with_substs(): casting pointer!");
val = consts::ptrcast(val, llptrty);
// Replace the self type (&Self or Box<Self>) with an opaque pointer.
let mptr = Load(bcx, GEPi(bcx, llvtable, &[vtable_index + VTABLE_OFFSET]));
- let llcallee_ty = type_of_fn_from_ty(ccx, opaque_fn_ty);
Callee {
bcx: bcx,
data: TraitItem(MethodData {
- llfn: PointerCast(bcx, mptr, llcallee_ty.ptr_to()),
+ llfn: PointerCast(bcx, mptr, type_of(ccx, opaque_fn_ty)),
llself: PointerCast(bcx, llself, Type::i8p(ccx)),
}),
ty: opaque_fn_ty
Type::func(&atys[..], &lloutputtype)
}
-// Given a function type and a count of ty params, construct an llvm type
-pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type {
- match fty.sty {
- ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
- // FIXME(#19925) once fn item types are
- // zero-sized, we'll need to do something here
- if f.abi == Abi::Rust || f.abi == Abi::RustCall {
- let sig = cx.tcx().erase_late_bound_regions(&f.sig);
- let sig = infer::normalize_associated_type(cx.tcx(), &sig);
- type_of_rust_fn(cx, None, &sig, f.abi)
- } else {
- foreign::lltype_for_foreign_fn(cx, fty)
- }
- }
- _ => {
- cx.sess().bug("type_of_fn_from_ty given non-closure, non-bare-fn")
- }
- }
-}
-
// A "sizing type" is an LLVM type, the size and alignment of which are
// guaranteed to be equivalent to what you would get out of `type_of()`. It's
// useful because:
ty::TySlice(ty) => in_memory_type_of(cx, ty),
ty::TyStr | ty::TyTrait(..) => Type::i8(cx),
- ty::TyFnDef(..) | ty::TyFnPtr(_) => {
- type_of_fn_from_ty(cx, t).ptr_to()
+ ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
+ // FIXME(#19925) once fn item types are
+ // zero-sized, we'll need to do something here
+ if f.abi == Abi::Rust || f.abi == Abi::RustCall {
+ let sig = cx.tcx().erase_late_bound_regions(&f.sig);
+ let sig = infer::normalize_associated_type(cx.tcx(), &sig);
+ type_of_rust_fn(cx, None, &sig, f.abi).ptr_to()
+ } else {
+ foreign::lltype_for_foreign_fn(cx, t).ptr_to()
+ }
}
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
ty::TyTuple(..) => {