@@ -213,11 +213,13 @@ impl PurityState {
213
213
}
214
214
}
215
215
216
- /// Whether `check_binop` allows overloaded operators to be invoked.
216
+ /// Whether `check_binop` is part of an assignment or not.
217
+ /// Used to know wether we allow user overloads and to print
218
+ /// better messages on error.
217
219
#[ deriving( Eq ) ]
218
- enum AllowOverloadedOperatorsFlag {
219
- AllowOverloadedOperators ,
220
- DontAllowOverloadedOperators ,
220
+ enum IsBinopAssignment {
221
+ SimpleBinop ,
222
+ BinopAssignment ,
221
223
}
222
224
223
225
#[ deriving( Clone ) ]
@@ -2086,7 +2088,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2086
2088
rhs : @ast:: Expr ,
2087
2089
// Used only in the error case
2088
2090
expected_result : Option < ty:: t > ,
2089
- allow_overloaded_operators : AllowOverloadedOperatorsFlag
2091
+ is_binop_assignment : IsBinopAssignment
2090
2092
) {
2091
2093
let tcx = fcx. ccx . tcx ;
2092
2094
@@ -2136,9 +2138,9 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2136
2138
2137
2139
}
2138
2140
2139
- // Check for overloaded operators if allowed .
2141
+ // Check for overloaded operators if not an assignment .
2140
2142
let result_t;
2141
- if allow_overloaded_operators == AllowOverloadedOperators {
2143
+ if is_binop_assignment == SimpleBinop {
2142
2144
result_t = check_user_binop ( fcx,
2143
2145
callee_id,
2144
2146
expr,
@@ -2150,13 +2152,14 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2150
2152
} else {
2151
2153
fcx. type_error_message ( expr. span ,
2152
2154
|actual| {
2153
- format ! ( "binary operation {} cannot be \
2154
- applied to type `{}`",
2155
- ast_util:: binop_to_str( op) ,
2156
- actual)
2155
+ format ! ( "binary assignment operation \
2156
+ {}= cannot be applied to type `{}`",
2157
+ ast_util:: binop_to_str( op) ,
2158
+ actual)
2157
2159
} ,
2158
2160
lhs_t,
2159
2161
None ) ;
2162
+ check_expr ( fcx, rhs) ;
2160
2163
result_t = ty:: mk_err ( ) ;
2161
2164
}
2162
2165
@@ -2760,7 +2763,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2760
2763
lhs,
2761
2764
rhs,
2762
2765
expected,
2763
- AllowOverloadedOperators ) ;
2766
+ SimpleBinop ) ;
2764
2767
2765
2768
let lhs_ty = fcx. expr_ty ( lhs) ;
2766
2769
let rhs_ty = fcx. expr_ty ( rhs) ;
@@ -2781,7 +2784,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2781
2784
lhs,
2782
2785
rhs,
2783
2786
expected,
2784
- DontAllowOverloadedOperators ) ;
2787
+ BinopAssignment ) ;
2785
2788
2786
2789
let lhs_t = fcx. expr_ty ( lhs) ;
2787
2790
let result_t = fcx. expr_ty ( expr) ;
0 commit comments