@@ -938,7 +938,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
938
938
call_expr_id : ast:: node_id ,
939
939
in_fty : ty:: t ,
940
940
callee_expr : @ast:: expr ,
941
- check_args : bool ,
942
941
args : ~[ @ast:: expr ] ) -> { fty : ty:: t , bot : bool } {
943
942
944
943
let mut bot = false ;
@@ -1028,15 +1027,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1028
1027
debug!(" checking the argument");
1029
1028
let formal_ty = formal_tys[i];
1030
1029
1031
- if check_args {
1032
- bot |= check_expr_with_unifier(
1033
- fcx, arg, Some(formal_ty),
1034
- || demand::assign(fcx, arg.span, formal_ty, arg)
1035
- );
1036
- } else {
1037
- demand::assign(fcx, arg.span, formal_ty, arg);
1038
- bot |= ty::type_is_bot(fcx.expr_ty(arg));
1039
- }
1030
+ bot |= check_expr_with_unifier(
1031
+ fcx, arg, Some(formal_ty),
1032
+ || demand::assign(fcx, arg.span, formal_ty, arg)
1033
+ );
1040
1034
}
1041
1035
}
1042
1036
}
@@ -1070,7 +1064,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1070
1064
// Call the generic checker.
1071
1065
let fty = {
1072
1066
let r = check_call_inner(fcx, sp, call_expr_id,
1073
- fn_ty, f, true, args);
1067
+ fn_ty, f, args);
1074
1068
bot |= r.bot;
1075
1069
r.fty
1076
1070
};
@@ -1126,8 +1120,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1126
1120
1127
1121
fn lookup_op_method(fcx: @fn_ctxt, op_ex: @ast::expr,
1128
1122
self_ex: @ast::expr, self_t: ty::t,
1129
- opname: ast::ident, check_args: bool,
1130
- args: ~[@ast::expr])
1123
+ opname: ast::ident, args: ~[@ast::expr])
1131
1124
-> Option<(ty::t, bool)>
1132
1125
{
1133
1126
match method::lookup(fcx, op_ex, self_ex,
@@ -1136,7 +1129,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1136
1129
let {fty: method_ty, bot: bot} = {
1137
1130
let method_ty = fcx.node_ty(op_ex.callee_id);
1138
1131
check_call_inner(fcx, op_ex.span, op_ex.id,
1139
- method_ty, op_ex, check_args, args)
1132
+ method_ty, op_ex, args)
1140
1133
};
1141
1134
fcx.ccx.method_map.insert(op_ex.id, origin);
1142
1135
Some((ty::ty_fn_ret(method_ty), bot))
@@ -1145,52 +1138,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1145
1138
}
1146
1139
}
1147
1140
1148
- fn check_rel_op(fcx: @fn_ctxt,
1149
- expr: @ast::expr,
1150
- op: ast::binop,
1151
- lhs: @ast::expr,
1152
- rhs: @ast::expr) -> bool
1153
- {
1154
- // We know that only things of equal type can be compared, so
1155
- // go ahead and unify the two types before we do anything else
1156
- // (with other operators, we must be much more careful not to
1157
- // make assumptions, due to the possibility of operator
1158
- // overloading; but overloaded == still enforces the
1159
- // requirement that only equal types are compared).
1160
- let tcx = fcx.ccx.tcx;
1161
- let lhs_bot = check_expr(fcx, lhs, None);
1162
- let lhs_t = fcx.expr_ty(lhs);
1163
- let rhs_bot = check_expr_with(fcx, rhs, lhs_t);
1164
-
1165
- let lhs_t = structurally_resolved_type(fcx, lhs.span, lhs_t);
1166
- if ty::is_binopable(tcx, lhs_t, op) {
1167
- let result_t = ty::mk_bool(tcx);
1168
- fcx.write_ty(expr.id, result_t);
1169
- return lhs_bot | rhs_bot;
1170
- }
1171
-
1172
- let (result, rhs_bot) =
1173
- check_user_binop(fcx, expr, lhs, lhs_t, op, false, rhs);
1174
- fcx.write_ty(expr.id, result);
1175
- return lhs_bot | rhs_bot;
1176
- }
1177
-
1178
1141
// could be either a expr_binop or an expr_assign_binop
1179
1142
fn check_binop(fcx: @fn_ctxt, expr: @ast::expr,
1180
1143
op: ast::binop,
1181
1144
lhs: @ast::expr,
1182
1145
rhs: @ast::expr) -> bool {
1183
1146
let tcx = fcx.ccx.tcx;
1184
1147
1185
- // Relational operators are different for type inferencing
1186
- // reasons.
1187
- match op {
1188
- ast::eq | ast::ne | ast::lt | ast::le | ast::ge | ast::gt => {
1189
- return check_rel_op(fcx, expr, op, lhs, rhs);
1190
- }
1191
- _ => {}
1192
- }
1193
-
1194
1148
let lhs_bot = check_expr(fcx, lhs, None);
1195
1149
let lhs_t = fcx.expr_ty(lhs);
1196
1150
let lhs_t = structurally_resolved_type(fcx, lhs.span, lhs_t);
@@ -1208,7 +1162,16 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1208
1162
let tvar = fcx.infcx().next_ty_var();
1209
1163
demand::suptype(fcx, expr.span, tvar, lhs_t);
1210
1164
let rhs_bot = check_expr_with(fcx, rhs, tvar);
1211
- let result_t = lhs_t;
1165
+
1166
+ let result_t = match op {
1167
+ ast::eq | ast::ne | ast::lt | ast::le | ast::ge | ast::gt => {
1168
+ ty::mk_bool(tcx)
1169
+ }
1170
+ _ => {
1171
+ lhs_t
1172
+ }
1173
+ };
1174
+
1212
1175
fcx.write_ty(expr.id, result_t);
1213
1176
return {
1214
1177
if !ast_util::lazy_binop(op) { lhs_bot | rhs_bot }
@@ -1217,22 +1180,21 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1217
1180
}
1218
1181
1219
1182
let (result, rhs_bot) =
1220
- check_user_binop(fcx, expr, lhs, lhs_t, op, true, rhs);
1183
+ check_user_binop(fcx, expr, lhs, lhs_t, op, rhs);
1221
1184
fcx.write_ty(expr.id, result);
1222
1185
return lhs_bot | rhs_bot;
1223
1186
}
1224
1187
1225
1188
fn check_user_binop(fcx: @fn_ctxt, ex: @ast::expr,
1226
1189
lhs_expr: @ast::expr, lhs_resolved_t: ty::t,
1227
- op: ast::binop, check_rhs: bool,
1228
- rhs: @ast::expr) -> (ty::t, bool)
1190
+ op: ast::binop, rhs: @ast::expr) -> (ty::t, bool)
1229
1191
{
1230
1192
let tcx = fcx.ccx.tcx;
1231
1193
match ast_util::binop_to_method_name(op) {
1232
1194
Some(name) => {
1233
1195
match lookup_op_method(fcx, ex, lhs_expr, lhs_resolved_t,
1234
1196
fcx.tcx().sess.ident_of(name),
1235
- check_rhs, ~[rhs]) {
1197
+ ~[rhs]) {
1236
1198
Some(pair) => return pair,
1237
1199
_ => ()
1238
1200
}
@@ -1266,7 +1228,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1266
1228
ex: @ast::expr,
1267
1229
rhs_expr: @ast::expr, rhs_t: ty::t) -> ty::t {
1268
1230
match lookup_op_method(fcx, ex, rhs_expr, rhs_t,
1269
- fcx.tcx().sess.ident_of(mname), true, ~[]) {
1231
+ fcx.tcx().sess.ident_of(mname), ~[]) {
1270
1232
Some((ret_ty, _)) => ret_ty,
1271
1233
_ => {
1272
1234
fcx.ccx.tcx.sess.span_err(
@@ -2073,7 +2035,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
2073
2035
let resolved = structurally_resolved_type(fcx, expr.span,
2074
2036
raw_base_t);
2075
2037
match lookup_op_method(fcx, expr, base, resolved,
2076
- tcx.sess.ident_of(~" index"), true,
2038
+ tcx.sess.ident_of(~" index"),
2077
2039
~[idx]) {
2078
2040
Some((ret_ty, _)) => fcx.write_ty(id, ret_ty),
2079
2041
_ => {
0 commit comments