Skip to content

Commit 3971b52

Browse files
committed
Use the right types for methods in trans_impl
This prevents misalignment between function and argument types in corner cases.
1 parent 71c1c15 commit 3971b52

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

src/comp/middle/trans.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, is_method: bool, inputs: [ty::arg],
115115

116116
// Given a function type and a count of ty params, construct an llvm type
117117
fn type_of_fn_from_ty(cx: @crate_ctxt, sp: span, fty: ty::t,
118-
param_bounds: [ty::param_bounds])
119-
: returns_non_ty_var(cx, fty) -> TypeRef {
118+
param_bounds: [ty::param_bounds]) -> TypeRef {
120119
// FIXME: Check should be unnecessary, b/c it's implied
121120
// by returns_non_ty_var(t). Make that a postcondition
122121
// (see Issue #586)
@@ -173,8 +172,6 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
173172
T_struct(tys)
174173
}
175174
ty::ty_fn(_) {
176-
// FIXME: could be a constraint on ty_fn
177-
check returns_non_ty_var(cx, t);
178175
T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, []))
179176
}
180177
ty::ty_native_fn(args, out) {
@@ -242,7 +239,6 @@ fn type_of_ty_param_bounds_and_ty(lcx: @local_ctxt, sp: span,
242239
let t = tpt.ty;
243240
alt ty::struct(cx.tcx, t) {
244241
ty::ty_fn(_) | ty::ty_native_fn(_, _) {
245-
check returns_non_ty_var(cx, t);
246242
ret type_of_fn_from_ty(cx, sp, t, *tpt.bounds);
247243
}
248244
_ {
@@ -5300,7 +5296,6 @@ fn collect_native_item(ccx: @crate_ctxt,
53005296
ast::native_abi_rust_intrinsic. {
53015297
// For intrinsics: link the function directly to the intrinsic
53025298
// function itself.
5303-
check returns_non_ty_var(ccx, node_type);
53045299
let fn_type = type_of_fn_from_ty(
53055300
ccx, sp, node_type,
53065301
vec::map(tps, {|p| param_bounds(ccx, p)}));

src/comp/middle/trans_closure.rs

-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ fn trans_expr_fn(bcx: @block_ctxt,
405405
if dest == ignore { ret bcx; }
406406
let ccx = bcx_ccx(bcx), bcx = bcx;
407407
let fty = node_id_type(ccx, id);
408-
check returns_non_ty_var(ccx, fty);
409408
let llfnty = type_of_fn_from_ty(ccx, sp, fty, []);
410409
let sub_cx = extend_path(bcx.fcx.lcx, ccx.names.next("anon"));
411410
let s = mangle_internal_name_by_path(ccx, sub_cx.path);
@@ -779,7 +778,6 @@ fn trans_bind_thunk(cx: @local_ctxt,
779778
// needs to take.
780779
let ccx = bcx_ccx(bcx);
781780

782-
check returns_non_ty_var(ccx, outgoing_fty);
783781
let lltargetty =
784782
type_of_fn_from_ty(ccx, sp, outgoing_fty, param_bounds);
785783
lltargetfn = PointerCast(bcx, lltargetfn, T_ptr(lltargetty));

src/comp/middle/trans_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ fn trans_dict_callee(bcx: @block_ctxt, e: @ast::expr, base: @ast::expr,
4444
let {bcx, val} = trans_self_arg(bcx, base);
4545
let dict = option::get(bcx.fcx.lltyparams[n_param].dicts)[n_bound];
4646
let method = ty::iface_methods(tcx, iface_id)[n_method];
47-
let bare_fn_ty = type_of_fn(bcx_ccx(bcx), ast_util::dummy_sp(),
48-
false, method.fty.inputs, method.fty.output,
49-
*method.tps);
47+
let fty = ty::expr_ty(tcx, e);
48+
let bare_fn_ty = type_of_fn_from_ty(bcx_ccx(bcx), ast_util::dummy_sp(),
49+
fty, *method.tps);
5050
let {inputs: bare_inputs, output} = llfn_arg_tys(bare_fn_ty);
5151
let fn_ty = T_fn([val_ty(dict)] + bare_inputs, output);
5252
let vtable = PointerCast(bcx, Load(bcx, GEPi(bcx, dict, [0, 0])),
@@ -63,7 +63,7 @@ fn trans_dict_callee(bcx: @block_ctxt, e: @ast::expr, base: @ast::expr,
6363
tydescs += [td.val];
6464
bcx = td.bcx;
6565
}
66-
generic = some({item_type: ty::mk_fn(tcx, method.fty),
66+
generic = some({item_type: fty,
6767
static_tis: tis,
6868
tydescs: tydescs,
6969
param_bounds: method.tps,

0 commit comments

Comments
 (0)