@@ -306,7 +306,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
306
306
if let Some ( missing_trait) = missing_trait {
307
307
if op. node == hir:: BinOpKind :: Add &&
308
308
self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
309
- rhs_ty, & mut err, true ) {
309
+ rhs_ty, & mut err, true , op ) {
310
310
// This has nothing here because it means we did string
311
311
// concatenation (e.g., "Hello " += "World!"). This means
312
312
// we don't want the note in the else clause to be emitted
@@ -327,10 +327,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
327
327
err. emit ( ) ;
328
328
}
329
329
IsAssign :: No => {
330
- let mut err = struct_span_err ! ( self . tcx. sess, expr . span, E0369 ,
330
+ let mut err = struct_span_err ! ( self . tcx. sess, op . span, E0369 ,
331
331
"binary operation `{}` cannot be applied to type `{}`" ,
332
332
op. node. as_str( ) ,
333
333
lhs_ty) ;
334
+
335
+ if !lhs_expr. span . eq ( & rhs_expr. span ) {
336
+ err. span_label ( lhs_expr. span , lhs_ty. to_string ( ) ) ;
337
+ err. span_label ( rhs_expr. span , rhs_ty. to_string ( ) ) ;
338
+ }
339
+
334
340
let mut suggested_deref = false ;
335
341
if let Ref ( _, mut rty, _) = lhs_ty. sty {
336
342
if {
@@ -380,7 +386,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
380
386
if let Some ( missing_trait) = missing_trait {
381
387
if op. node == hir:: BinOpKind :: Add &&
382
388
self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
383
- rhs_ty, & mut err, false ) {
389
+ rhs_ty, & mut err, false , op ) {
384
390
// This has nothing here because it means we did string
385
391
// concatenation (e.g., "Hello " + "World!"). This means
386
392
// we don't want the note in the else clause to be emitted
@@ -418,6 +424,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
418
424
rhs_ty : Ty < ' tcx > ,
419
425
err : & mut errors:: DiagnosticBuilder < ' _ > ,
420
426
is_assign : bool ,
427
+ op : hir:: BinOp ,
421
428
) -> bool {
422
429
let source_map = self . tcx . sess . source_map ( ) ;
423
430
let msg = "`to_owned()` can be used to create an owned `String` \
@@ -431,7 +438,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
431
438
( & Ref ( _, l_ty, _) , & Ref ( _, r_ty, _) )
432
439
if l_ty. sty == Str && r_ty. sty == Str => {
433
440
if !is_assign {
434
- err. span_label ( expr . span ,
441
+ err. span_label ( op . span ,
435
442
"`+` can't be used to concatenate two `&str` strings" ) ;
436
443
match source_map. span_to_snippet ( lhs_expr. span ) {
437
444
Ok ( lstring) => err. span_suggestion (
0 commit comments