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.
This commit is contained in:
Marijn Haverbeke 2011-07-08 15:52:54 +02:00
parent 381505f947
commit eeda0f4ab1
2 changed files with 4 additions and 17 deletions

View File

@ -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 }

View File

@ -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);
}