From eeda0f4ab1f01d2f86a57e6975fdac1cc28d04e0 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 8 Jul 2011 15:52:54 +0200 Subject: [PATCH] Don't unbox types in ty::is_binopable, do it on typeck side instead Closes issue #631 Removes ty::strip_boxes entirely, since unboxing is now more complicated anyway. --- src/comp/middle/ty.rs | 16 +--------------- src/comp/middle/typeck.rs | 5 +++-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index a848f7267022..1cd8a8756e9a 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -2897,20 +2897,6 @@ fn ret_ty_of_fn(ctxt cx, ast::node_id id) -> t { ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id)); } - -// NB: This function requires that the given type has no variables. So, inside -// typeck, you should use typeck::do_autoderef() instead. -fn strip_boxes(&ctxt cx, &ty::t t) -> ty::t { - auto t1 = t; - while (true) { - alt (struct(cx, t1)) { - case (ty::ty_box(?inner)) { t1 = inner.ty; } - case (_) { ret t1; } - } - } - fail; -} - fn is_binopable(&ctxt cx, t ty, ast::binop op) -> bool { const int tycat_other = 0; @@ -2955,7 +2941,7 @@ fn is_binopable(&ctxt cx, t ty, ast::binop op) -> bool { } fn tycat(&ctxt cx, t ty) -> int { - alt (struct(cx, strip_boxes(cx, ty))) { + alt (struct(cx, ty)) { case (ty_bool) { tycat_bool } case (ty_int) { tycat_int } case (ty_uint) { tycat_int } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index fde82279fd02..f1dc08001cf8 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1620,7 +1620,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { auto rhs_t = expr_ty(fcx.ccx.tcx, rhs); demand::autoderef(fcx, rhs.span, lhs_t, rhs_t, AUTODEREF_OK); - check_binop_type_compat(fcx, expr.span, lhs_t, binop); + auto deref_t = do_autoderef(fcx, expr.span, lhs_t); + check_binop_type_compat(fcx, expr.span, deref_t, binop); auto t = alt (binop) { case (ast::eq) { ty::mk_bool(fcx.ccx.tcx) } @@ -1629,7 +1630,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { case (ast::ne) { ty::mk_bool(fcx.ccx.tcx) } case (ast::ge) { ty::mk_bool(fcx.ccx.tcx) } case (ast::gt) { ty::mk_bool(fcx.ccx.tcx) } - case (_) { do_autoderef(fcx, expr.span, lhs_t) } + case (_) { deref_t } }; write::ty_only_fixup(fcx, id, t); }