@@ -306,6 +306,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
306306 lang_item_for_op ( self . tcx , Op :: Binary ( op, is_assign) , op. span ) ;
307307 let missing_trait = trait_def_id
308308 . map ( |def_id| with_no_trimmed_paths ! ( self . tcx. def_path_str( def_id) ) ) ;
309+ let mut path = None ;
310+ let lhs_ty_str = self . tcx . short_string ( lhs_ty, & mut path) ;
311+ let rhs_ty_str = self . tcx . short_string ( rhs_ty, & mut path) ;
309312 let ( mut err, output_def_id) = match is_assign {
310313 IsAssign :: Yes => {
311314 let mut err = struct_span_code_err ! (
@@ -314,53 +317,54 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
314317 E0368 ,
315318 "binary assignment operation `{}=` cannot be applied to type `{}`" ,
316319 op. node. as_str( ) ,
317- lhs_ty ,
320+ lhs_ty_str ,
318321 ) ;
319322 err. span_label (
320323 lhs_expr. span ,
321- format ! ( "cannot use `{}=` on type `{}`" , op. node. as_str( ) , lhs_ty ) ,
324+ format ! ( "cannot use `{}=` on type `{}`" , op. node. as_str( ) , lhs_ty_str ) ,
322325 ) ;
323326 self . note_unmet_impls_on_type ( & mut err, errors, false ) ;
324327 ( err, None )
325328 }
326329 IsAssign :: No => {
327330 let message = match op. node {
328331 hir:: BinOpKind :: Add => {
329- format ! ( "cannot add `{rhs_ty }` to `{lhs_ty }`" )
332+ format ! ( "cannot add `{rhs_ty_str }` to `{lhs_ty_str }`" )
330333 }
331334 hir:: BinOpKind :: Sub => {
332- format ! ( "cannot subtract `{rhs_ty }` from `{lhs_ty }`" )
335+ format ! ( "cannot subtract `{rhs_ty_str }` from `{lhs_ty_str }`" )
333336 }
334337 hir:: BinOpKind :: Mul => {
335- format ! ( "cannot multiply `{lhs_ty }` by `{rhs_ty }`" )
338+ format ! ( "cannot multiply `{lhs_ty_str }` by `{rhs_ty_str }`" )
336339 }
337340 hir:: BinOpKind :: Div => {
338- format ! ( "cannot divide `{lhs_ty }` by `{rhs_ty }`" )
341+ format ! ( "cannot divide `{lhs_ty_str }` by `{rhs_ty_str }`" )
339342 }
340343 hir:: BinOpKind :: Rem => {
341344 format ! (
342- "cannot calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`"
345+ "cannot calculate the remainder of `{lhs_ty_str}` divided by \
346+ `{rhs_ty_str}`"
343347 )
344348 }
345349 hir:: BinOpKind :: BitAnd => {
346- format ! ( "no implementation for `{lhs_ty } & {rhs_ty }`" )
350+ format ! ( "no implementation for `{lhs_ty_str } & {rhs_ty_str }`" )
347351 }
348352 hir:: BinOpKind :: BitXor => {
349- format ! ( "no implementation for `{lhs_ty } ^ {rhs_ty }`" )
353+ format ! ( "no implementation for `{lhs_ty_str } ^ {rhs_ty_str }`" )
350354 }
351355 hir:: BinOpKind :: BitOr => {
352- format ! ( "no implementation for `{lhs_ty } | {rhs_ty }`" )
356+ format ! ( "no implementation for `{lhs_ty_str } | {rhs_ty_str }`" )
353357 }
354358 hir:: BinOpKind :: Shl => {
355- format ! ( "no implementation for `{lhs_ty } << {rhs_ty }`" )
359+ format ! ( "no implementation for `{lhs_ty_str } << {rhs_ty_str }`" )
356360 }
357361 hir:: BinOpKind :: Shr => {
358- format ! ( "no implementation for `{lhs_ty } >> {rhs_ty }`" )
362+ format ! ( "no implementation for `{lhs_ty_str } >> {rhs_ty_str }`" )
359363 }
360364 _ => format ! (
361365 "binary operation `{}` cannot be applied to type `{}`" ,
362366 op. node. as_str( ) ,
363- lhs_ty
367+ lhs_ty_str ,
364368 ) ,
365369 } ;
366370 let output_def_id = trait_def_id. and_then ( |def_id| {
@@ -375,14 +379,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
375379 let mut err =
376380 struct_span_code_err ! ( self . dcx( ) , op. span, E0369 , "{message}" ) ;
377381 if !lhs_expr. span . eq ( & rhs_expr. span ) {
378- err. span_label ( lhs_expr. span , lhs_ty . to_string ( ) ) ;
379- err. span_label ( rhs_expr. span , rhs_ty . to_string ( ) ) ;
382+ err. span_label ( lhs_expr. span , lhs_ty_str . clone ( ) ) ;
383+ err. span_label ( rhs_expr. span , rhs_ty_str ) ;
380384 }
381385 let suggest_derive = self . can_eq ( self . param_env , lhs_ty, rhs_ty) ;
382386 self . note_unmet_impls_on_type ( & mut err, errors, suggest_derive) ;
383387 ( err, output_def_id)
384388 }
385389 } ;
390+ * err. long_ty_path ( ) = path;
386391
387392 // Try to suggest a semicolon if it's `A \n *B` where `B` is a place expr
388393 let maybe_missing_semi = self . check_for_missing_semi ( expr, & mut err) ;
@@ -417,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
417422 IsAssign :: Yes => "=" ,
418423 IsAssign :: No => "" ,
419424 } ,
420- lhs_deref_ty,
425+ self . tcx . short_string ( lhs_deref_ty, err . long_ty_path ( ) ) ,
421426 ) ;
422427 err. span_suggestion_verbose (
423428 lhs_expr. span . shrink_to_lo ( ) ,
@@ -443,8 +448,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
443448 )
444449 . is_ok ( )
445450 {
446- let op_str = op. node . as_str ( ) ;
447- err. note ( format ! ( "an implementation for `{lhs_adjusted_ty} {op_str} {rhs_adjusted_ty}` exists" ) ) ;
451+ let lhs = self . tcx . short_string ( lhs_adjusted_ty, err. long_ty_path ( ) ) ;
452+ let rhs = self . tcx . short_string ( rhs_adjusted_ty, err. long_ty_path ( ) ) ;
453+ let op = op. node . as_str ( ) ;
454+ err. note ( format ! ( "an implementation for `{lhs} {op} {rhs}` exists" ) ) ;
448455
449456 if let Some ( lhs_new_mutbl) = lhs_new_mutbl
450457 && let Some ( rhs_new_mutbl) = rhs_new_mutbl
@@ -628,7 +635,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
628635 // When we know that a missing bound is responsible, we don't show
629636 // this note as it is redundant.
630637 err. note ( format ! (
631- "the trait `{missing_trait}` is not implemented for `{lhs_ty }`"
638+ "the trait `{missing_trait}` is not implemented for `{lhs_ty_str }`"
632639 ) ) ;
633640 }
634641 }
@@ -654,24 +661,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
654661 hir:: BinOpKind :: Sub => {
655662 if lhs_ty. is_unsafe_ptr ( ) && rhs_ty. is_integral ( ) {
656663 err. multipart_suggestion (
657- "consider using `wrapping_sub` or `sub` for pointer - {integer}" ,
664+ "consider using `wrapping_sub` or `sub` for \
665+ pointer - {integer}",
658666 vec ! [
659- ( lhs_expr. span. between( rhs_expr. span) , ".wrapping_sub(" . to_owned( ) ) ,
667+ (
668+ lhs_expr. span. between( rhs_expr. span) ,
669+ ".wrapping_sub(" . to_owned( ) ,
670+ ) ,
660671 ( rhs_expr. span. shrink_to_hi( ) , ")" . to_owned( ) ) ,
661672 ] ,
662- Applicability :: MaybeIncorrect
673+ Applicability :: MaybeIncorrect ,
663674 ) ;
664675 }
665676
666677 if lhs_ty. is_unsafe_ptr ( ) && rhs_ty. is_unsafe_ptr ( ) {
667678 err. multipart_suggestion (
668- "consider using `offset_from` for pointer - pointer if the pointers point to the same allocation" ,
679+ "consider using `offset_from` for pointer - pointer if the \
680+ pointers point to the same allocation",
669681 vec ! [
670682 ( lhs_expr. span. shrink_to_lo( ) , "unsafe { " . to_owned( ) ) ,
671- ( lhs_expr. span. between( rhs_expr. span) , ".offset_from(" . to_owned( ) ) ,
683+ (
684+ lhs_expr. span. between( rhs_expr. span) ,
685+ ".offset_from(" . to_owned( ) ,
686+ ) ,
672687 ( rhs_expr. span. shrink_to_hi( ) , ") }" . to_owned( ) ) ,
673688 ] ,
674- Applicability :: MaybeIncorrect
689+ Applicability :: MaybeIncorrect ,
675690 ) ;
676691 }
677692 }
@@ -793,14 +808,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
793808 Err ( errors) => {
794809 let actual = self . resolve_vars_if_possible ( operand_ty) ;
795810 let guar = actual. error_reported ( ) . err ( ) . unwrap_or_else ( || {
811+ let mut file = None ;
812+ let ty_str = self . tcx . short_string ( actual, & mut file) ;
796813 let mut err = struct_span_code_err ! (
797814 self . dcx( ) ,
798815 ex. span,
799816 E0600 ,
800- "cannot apply unary operator `{}` to type `{}`" ,
817+ "cannot apply unary operator `{}` to type `{ty_str }`" ,
801818 op. as_str( ) ,
802- actual
803819 ) ;
820+ * err. long_ty_path ( ) = file;
804821 err. span_label (
805822 ex. span ,
806823 format ! ( "cannot apply unary operator `{}`" , op. as_str( ) ) ,
0 commit comments