@@ -306,6 +306,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
306
306
lang_item_for_op ( self . tcx , Op :: Binary ( op, is_assign) , op. span ) ;
307
307
let missing_trait = trait_def_id
308
308
. 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) ;
309
312
let ( mut err, output_def_id) = match is_assign {
310
313
IsAssign :: Yes => {
311
314
let mut err = struct_span_code_err ! (
@@ -314,53 +317,54 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
314
317
E0368 ,
315
318
"binary assignment operation `{}=` cannot be applied to type `{}`" ,
316
319
op. node. as_str( ) ,
317
- lhs_ty ,
320
+ lhs_ty_str ,
318
321
) ;
319
322
err. span_label (
320
323
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 ) ,
322
325
) ;
323
326
self . note_unmet_impls_on_type ( & mut err, errors, false ) ;
324
327
( err, None )
325
328
}
326
329
IsAssign :: No => {
327
330
let message = match op. node {
328
331
hir:: BinOpKind :: Add => {
329
- format ! ( "cannot add `{rhs_ty }` to `{lhs_ty }`" )
332
+ format ! ( "cannot add `{rhs_ty_str }` to `{lhs_ty_str }`" )
330
333
}
331
334
hir:: BinOpKind :: Sub => {
332
- format ! ( "cannot subtract `{rhs_ty }` from `{lhs_ty }`" )
335
+ format ! ( "cannot subtract `{rhs_ty_str }` from `{lhs_ty_str }`" )
333
336
}
334
337
hir:: BinOpKind :: Mul => {
335
- format ! ( "cannot multiply `{lhs_ty }` by `{rhs_ty }`" )
338
+ format ! ( "cannot multiply `{lhs_ty_str }` by `{rhs_ty_str }`" )
336
339
}
337
340
hir:: BinOpKind :: Div => {
338
- format ! ( "cannot divide `{lhs_ty }` by `{rhs_ty }`" )
341
+ format ! ( "cannot divide `{lhs_ty_str }` by `{rhs_ty_str }`" )
339
342
}
340
343
hir:: BinOpKind :: Rem => {
341
344
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}`"
343
347
)
344
348
}
345
349
hir:: BinOpKind :: BitAnd => {
346
- format ! ( "no implementation for `{lhs_ty } & {rhs_ty }`" )
350
+ format ! ( "no implementation for `{lhs_ty_str } & {rhs_ty_str }`" )
347
351
}
348
352
hir:: BinOpKind :: BitXor => {
349
- format ! ( "no implementation for `{lhs_ty } ^ {rhs_ty }`" )
353
+ format ! ( "no implementation for `{lhs_ty_str } ^ {rhs_ty_str }`" )
350
354
}
351
355
hir:: BinOpKind :: BitOr => {
352
- format ! ( "no implementation for `{lhs_ty } | {rhs_ty }`" )
356
+ format ! ( "no implementation for `{lhs_ty_str } | {rhs_ty_str }`" )
353
357
}
354
358
hir:: BinOpKind :: Shl => {
355
- format ! ( "no implementation for `{lhs_ty } << {rhs_ty }`" )
359
+ format ! ( "no implementation for `{lhs_ty_str } << {rhs_ty_str }`" )
356
360
}
357
361
hir:: BinOpKind :: Shr => {
358
- format ! ( "no implementation for `{lhs_ty } >> {rhs_ty }`" )
362
+ format ! ( "no implementation for `{lhs_ty_str } >> {rhs_ty_str }`" )
359
363
}
360
364
_ => format ! (
361
365
"binary operation `{}` cannot be applied to type `{}`" ,
362
366
op. node. as_str( ) ,
363
- lhs_ty
367
+ lhs_ty_str ,
364
368
) ,
365
369
} ;
366
370
let output_def_id = trait_def_id. and_then ( |def_id| {
@@ -375,14 +379,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
375
379
let mut err =
376
380
struct_span_code_err ! ( self . dcx( ) , op. span, E0369 , "{message}" ) ;
377
381
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 ) ;
380
384
}
381
385
let suggest_derive = self . can_eq ( self . param_env , lhs_ty, rhs_ty) ;
382
386
self . note_unmet_impls_on_type ( & mut err, errors, suggest_derive) ;
383
387
( err, output_def_id)
384
388
}
385
389
} ;
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
+ }
386
399
387
400
// Try to suggest a semicolon if it's `A \n *B` where `B` is a place expr
388
401
let maybe_missing_semi = self . check_for_missing_semi ( expr, & mut err) ;
0 commit comments