@@ -458,13 +458,25 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
458
458
being coerced, none found") ;
459
459
return ;
460
460
} else if diff_fields. len ( ) > 1 {
461
- span_err ! ( tcx. sess, span, E0375 ,
462
- "the trait `CoerceUnsized` may only be implemented \
463
- for a coercion between structures with one field \
464
- being coerced, but {} fields need coercions: {}",
465
- diff_fields. len( ) , diff_fields. iter( ) . map( |& ( i, a, b) | {
466
- format!( "{} ({} to {})" , fields[ i] . name, a, b)
467
- } ) . collect:: <Vec <_>>( ) . join( ", " ) ) ;
461
+ let item = tcx. map . expect_item ( impl_node_id) ;
462
+ let span = if let ItemImpl ( _, _, _, Some ( ref t) , _, _) = item. node {
463
+ t. path . span
464
+ } else {
465
+ tcx. map . span ( impl_node_id)
466
+ } ;
467
+
468
+ let mut err = struct_span_err ! ( tcx. sess, span, E0375 ,
469
+ "implementing the trait `CoerceUnsized` \
470
+ requires multiple coercions") ;
471
+ err. note ( "`CoerceUnsized` may only be implemented for \
472
+ a coercion between structures with one field being coerced") ;
473
+ err. note ( & format ! ( "currently, {} fields need coercions: {}" ,
474
+ diff_fields. len( ) ,
475
+ diff_fields. iter( ) . map( |& ( i, a, b) | {
476
+ format!( "{} ({} to {})" , fields[ i] . name, a, b)
477
+ } ) . collect:: <Vec <_>>( ) . join( ", " ) ) ) ;
478
+ err. span_label ( span, & format ! ( "requires multiple coercions" ) ) ;
479
+ err. emit ( ) ;
468
480
return ;
469
481
}
470
482
0 commit comments