about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-04 22:12:43 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-04 22:12:48 +0100
commit3971b520bcdd556ff78120c77ffd13785e1c3695 (patch)
treed56e13460747f0afb29d294a253c21b6c1f7b330
parent71c1c1580596e888f4bf0941f13f14c8bb109c23 (diff)
downloadrust-3971b520bcdd556ff78120c77ffd13785e1c3695.tar.gz
rust-3971b520bcdd556ff78120c77ffd13785e1c3695.zip
Use the right types for methods in trans_impl
This prevents misalignment between function and argument
types in corner cases.
-rw-r--r--src/comp/middle/trans.rs7
-rw-r--r--src/comp/middle/trans_closure.rs2
-rw-r--r--src/comp/middle/trans_impl.rs8
3 files changed, 5 insertions, 12 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 709a5e63792..c279c0a9b49 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -115,8 +115,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, is_method: bool, inputs: [ty::arg],
 
 // Given a function type and a count of ty params, construct an llvm type
 fn type_of_fn_from_ty(cx: @crate_ctxt, sp: span, fty: ty::t,
-                      param_bounds: [ty::param_bounds])
-    : returns_non_ty_var(cx, fty) -> TypeRef {
+                      param_bounds: [ty::param_bounds]) -> TypeRef {
     // FIXME: Check should be unnecessary, b/c it's implied
     // by returns_non_ty_var(t). Make that a postcondition
     // (see Issue #586)
@@ -173,8 +172,6 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
         T_struct(tys)
       }
       ty::ty_fn(_) {
-        // FIXME: could be a constraint on ty_fn
-        check returns_non_ty_var(cx, t);
         T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, []))
       }
       ty::ty_native_fn(args, out) {
@@ -242,7 +239,6 @@ fn type_of_ty_param_bounds_and_ty(lcx: @local_ctxt, sp: span,
     let t = tpt.ty;
     alt ty::struct(cx.tcx, t) {
       ty::ty_fn(_) | ty::ty_native_fn(_, _) {
-        check returns_non_ty_var(cx, t);
         ret type_of_fn_from_ty(cx, sp, t, *tpt.bounds);
       }
       _ {
@@ -5300,7 +5296,6 @@ fn collect_native_item(ccx: @crate_ctxt,
           ast::native_abi_rust_intrinsic. {
             // For intrinsics: link the function directly to the intrinsic
             // function itself.
-            check returns_non_ty_var(ccx, node_type);
             let fn_type = type_of_fn_from_ty(
                 ccx, sp, node_type,
                 vec::map(tps, {|p| param_bounds(ccx, p)}));
diff --git a/src/comp/middle/trans_closure.rs b/src/comp/middle/trans_closure.rs
index 66b0c775533..7759072f028 100644
--- a/src/comp/middle/trans_closure.rs
+++ b/src/comp/middle/trans_closure.rs
@@ -405,7 +405,6 @@ fn trans_expr_fn(bcx: @block_ctxt,
     if dest == ignore { ret bcx; }
     let ccx = bcx_ccx(bcx), bcx = bcx;
     let fty = node_id_type(ccx, id);
-    check returns_non_ty_var(ccx, fty);
     let llfnty = type_of_fn_from_ty(ccx, sp, fty, []);
     let sub_cx = extend_path(bcx.fcx.lcx, ccx.names.next("anon"));
     let s = mangle_internal_name_by_path(ccx, sub_cx.path);
@@ -779,7 +778,6 @@ fn trans_bind_thunk(cx: @local_ctxt,
     // needs to take.
     let ccx = bcx_ccx(bcx);
 
-    check returns_non_ty_var(ccx, outgoing_fty);
     let lltargetty =
         type_of_fn_from_ty(ccx, sp, outgoing_fty, param_bounds);
     lltargetfn = PointerCast(bcx, lltargetfn, T_ptr(lltargetty));
diff --git a/src/comp/middle/trans_impl.rs b/src/comp/middle/trans_impl.rs
index d67fbedf8a4..04bff49877f 100644
--- a/src/comp/middle/trans_impl.rs
+++ b/src/comp/middle/trans_impl.rs
@@ -44,9 +44,9 @@ fn trans_dict_callee(bcx: @block_ctxt, e: @ast::expr, base: @ast::expr,
     let {bcx, val} = trans_self_arg(bcx, base);
     let dict = option::get(bcx.fcx.lltyparams[n_param].dicts)[n_bound];
     let method = ty::iface_methods(tcx, iface_id)[n_method];
-    let bare_fn_ty = type_of_fn(bcx_ccx(bcx), ast_util::dummy_sp(),
-                                false, method.fty.inputs, method.fty.output,
-                                *method.tps);
+    let fty = ty::expr_ty(tcx, e);
+    let bare_fn_ty = type_of_fn_from_ty(bcx_ccx(bcx), ast_util::dummy_sp(),
+                                        fty, *method.tps);
     let {inputs: bare_inputs, output} = llfn_arg_tys(bare_fn_ty);
     let fn_ty = T_fn([val_ty(dict)] + bare_inputs, output);
     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,
             tydescs += [td.val];
             bcx = td.bcx;
         }
-        generic = some({item_type: ty::mk_fn(tcx, method.fty),
+        generic = some({item_type: fty,
                         static_tis: tis,
                         tydescs: tydescs,
                         param_bounds: method.tps,