@@ -868,6 +868,16 @@ fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool {
868
868
check_expr ( fcx, expr, Some ( expected) )
869
869
}
870
870
871
+ fn check_expr_with_assignability ( fcx : @fn_ctxt ,
872
+ expr : @ast:: expr ,
873
+ expected : ty:: t )
874
+ -> bool {
875
+ do check_expr_with_unifier ( fcx, expr, Some ( expected) ) {
876
+ demand:: assign ( fcx, expr. span , expected, expr)
877
+ }
878
+ }
879
+
880
+
871
881
fn check_expr ( fcx : @fn_ctxt , expr : @ast:: expr ,
872
882
expected : Option < ty:: t > ) -> bool {
873
883
return do check_expr_with_unifier ( fcx, expr, expected) {
@@ -1072,11 +1082,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1072
1082
DontDerefArgs => {}
1073
1083
}
1074
1084
1075
- bot |= check_expr_with_unifier(
1076
- fcx, *arg, Some(formal_ty),
1077
- || demand::assign(fcx, arg.span,
1078
- formal_ty, *arg)
1079
- );
1085
+ bot |= check_expr_with_assignability(fcx, *arg, formal_ty);
1080
1086
fcx.write_ty(arg.id, fcx.expr_ty(*arg));
1081
1087
1082
1088
}
@@ -1087,10 +1093,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1087
1093
}
1088
1094
1089
1095
// A generic function for checking assignment expressions
1090
- fn check_assignment(fcx: @fn_ctxt, _sp: span, lhs: @ast::expr,
1091
- rhs: @ast::expr, id: ast::node_id) -> bool {
1096
+ fn check_assignment(fcx: @fn_ctxt,
1097
+ lhs: @ast::expr,
1098
+ rhs: @ast::expr,
1099
+ id: ast::node_id)
1100
+ -> bool {
1092
1101
let mut bot = check_expr(fcx, lhs, None);
1093
- bot |= check_expr_with(fcx, rhs, fcx.expr_ty(lhs));
1102
+ let lhs_type = fcx.expr_ty(lhs);
1103
+ bot |= check_expr_with_assignability(fcx, rhs, lhs_type);
1094
1104
fcx.write_ty(id, ty::mk_nil(fcx.ccx.tcx));
1095
1105
return bot;
1096
1106
}
@@ -1908,10 +1918,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1908
1918
};
1909
1919
}
1910
1920
ast::expr_assign(lhs, rhs) => {
1911
- bot = check_assignment(fcx, expr.span, lhs, rhs, id);
1921
+ bot = check_assignment(fcx, lhs, rhs, id);
1912
1922
}
1913
1923
ast::expr_swap(lhs, rhs) => {
1914
- bot = check_assignment(fcx, expr.span, lhs, rhs, id);
1924
+ bot = check_assignment(fcx, lhs, rhs, id);
1915
1925
}
1916
1926
ast::expr_if(cond, thn, elsopt) => {
1917
1927
bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) |
@@ -2246,7 +2256,7 @@ fn require_integral(fcx: @fn_ctxt, sp: span, t: ty::t) {
2246
2256
fn check_decl_initializer( fcx: @fn_ctxt, nid: ast:: node_id,
2247
2257
init: @ast:: expr) -> bool {
2248
2258
let lty = ty:: mk_var( fcx. ccx. tcx, lookup_local( fcx, init. span, nid) ) ;
2249
- return check_expr_with ( fcx, init, lty) ;
2259
+ return check_expr_with_assignability ( fcx, init, lty) ;
2250
2260
}
2251
2261
2252
2262
fn check_decl_local( fcx: @fn_ctxt, local: @ast:: local) -> bool {
0 commit comments