@@ -184,9 +184,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
184
184
// particularly for things like `String + &String`.
185
185
let rhs_ty_var = self . next_ty_var ( TypeVariableOrigin :: MiscVariable ( rhs_expr. span ) ) ;
186
186
187
- let return_ty = match self . lookup_op_method ( expr, lhs_ty, vec ! [ rhs_ty_var] ,
188
- Symbol :: intern ( name) , trait_def_id,
189
- lhs_expr) {
187
+ let return_ty = self . lookup_op_method ( expr, lhs_ty, vec ! [ rhs_ty_var] ,
188
+ Symbol :: intern ( name) , trait_def_id,
189
+ lhs_expr) ;
190
+
191
+ // see `NB` above
192
+ let rhs_ty = self . check_expr_coercable_to_type ( rhs_expr, rhs_ty_var) ;
193
+
194
+ let return_ty = match return_ty {
190
195
Ok ( return_ty) => return_ty,
191
196
Err ( ( ) ) => {
192
197
// error types are considered "builtin"
@@ -209,7 +214,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
209
214
210
215
if let TypeVariants :: TyRef ( _, ref ty_mut) = lhs_ty. sty {
211
216
if !self . infcx . type_moves_by_default ( ty_mut. ty , lhs_expr. span ) &&
212
- self . lookup_op_method ( expr, ty_mut. ty , vec ! [ rhs_ty_var ] ,
217
+ self . lookup_op_method ( expr, ty_mut. ty , vec ! [ rhs_ty ] ,
213
218
Symbol :: intern ( name) , trait_def_id,
214
219
lhs_expr) . is_ok ( ) {
215
220
err. note (
@@ -240,7 +245,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
240
245
if let Some ( missing_trait) = missing_trait {
241
246
if missing_trait == "std::ops::Add" &&
242
247
self . check_str_addition ( expr, lhs_expr, lhs_ty,
243
- rhs_expr, rhs_ty_var , & mut err) {
248
+ rhs_expr, rhs_ty , & mut err) {
244
249
// This has nothing here because it means we did string
245
250
// concatenation (e.g. "Hello " + "World!"). This means
246
251
// we don't want the note in the else clause to be emitted
@@ -257,9 +262,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
257
262
}
258
263
} ;
259
264
260
- // see `NB` above
261
- self . check_expr_coercable_to_type ( rhs_expr, rhs_ty_var) ;
262
-
263
265
( rhs_ty_var, return_ty)
264
266
}
265
267
@@ -268,12 +270,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
268
270
lhs_expr : & ' gcx hir:: Expr ,
269
271
lhs_ty : Ty < ' tcx > ,
270
272
rhs_expr : & ' gcx hir:: Expr ,
271
- rhs_ty_var : Ty < ' tcx > ,
273
+ rhs_ty : Ty < ' tcx > ,
272
274
mut err : & mut errors:: DiagnosticBuilder ) -> bool {
273
275
// If this function returns true it means a note was printed, so we don't need
274
276
// to print the normal "implementation of `std::ops::Add` might be missing" note
275
277
let mut is_string_addition = false ;
276
- let rhs_ty = self . check_expr_coercable_to_type ( rhs_expr, rhs_ty_var) ;
277
278
if let TyRef ( _, l_ty) = lhs_ty. sty {
278
279
if let TyRef ( _, r_ty) = rhs_ty. sty {
279
280
if l_ty. ty . sty == TyStr && r_ty. ty . sty == TyStr {
0 commit comments