@@ -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_ty_string ( lhs_ty, & mut path) ;
311+ let rhs_ty_str = self . tcx . short_ty_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,23 @@ 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 ) ;
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+ if let Some ( path) = path {
391+ err. note ( format ! (
392+ "the full type name has been written to '{}'" ,
393+ path. display( )
394+ ) ) ;
395+ err. note (
396+ "consider using `--verbose` to print the full type name to the console" ,
397+ ) ;
398+ }
386399
387400 // Try to suggest a semicolon if it's `A \n *B` where `B` is a place expr
388401 let maybe_missing_semi = self . check_for_missing_semi ( expr, & mut err) ;
0 commit comments