@@ -306,7 +306,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
306306 if let Some ( missing_trait) = missing_trait {
307307 if op. node == hir:: BinOpKind :: Add &&
308308 self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
309- rhs_ty, & mut err, true ) {
309+ rhs_ty, & mut err, true , op ) {
310310 // This has nothing here because it means we did string
311311 // concatenation (e.g., "Hello " += "World!"). This means
312312 // 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> {
327327 err. emit ( ) ;
328328 }
329329 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 ,
331331 "binary operation `{}` cannot be applied to type `{}`" ,
332332 op. node. as_str( ) ,
333333 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+
334340 let mut suggested_deref = false ;
335341 if let Ref ( _, mut rty, _) = lhs_ty. sty {
336342 if {
@@ -380,7 +386,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
380386 if let Some ( missing_trait) = missing_trait {
381387 if op. node == hir:: BinOpKind :: Add &&
382388 self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
383- rhs_ty, & mut err, false ) {
389+ rhs_ty, & mut err, false , op ) {
384390 // This has nothing here because it means we did string
385391 // concatenation (e.g., "Hello " + "World!"). This means
386392 // 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> {
418424 rhs_ty : Ty < ' tcx > ,
419425 err : & mut errors:: DiagnosticBuilder < ' _ > ,
420426 is_assign : bool ,
427+ op : hir:: BinOp ,
421428 ) -> bool {
422429 let source_map = self . tcx . sess . source_map ( ) ;
423430 let msg = "`to_owned()` can be used to create an owned `String` \
@@ -431,7 +438,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
431438 ( & Ref ( _, l_ty, _) , & Ref ( _, r_ty, _) )
432439 if l_ty. sty == Str && r_ty. sty == Str => {
433440 if !is_assign {
434- err. span_label ( expr . span ,
441+ err. span_label ( op . span ,
435442 "`+` can't be used to concatenate two `&str` strings" ) ;
436443 match source_map. span_to_snippet ( lhs_expr. span ) {
437444 Ok ( lstring) => err. span_suggestion (
0 commit comments