@@ -979,10 +979,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
979
979
980
980
let span = cause. span ( & self . tcx ) ;
981
981
982
- diag. span_label ( span, terr. to_string ( ) ) ;
983
- if let Some ( ( sp, msg) ) = secondary_span {
984
- diag. span_label ( sp, msg) ;
985
- }
982
+ // Ignore msg for object safe coercion
983
+ // since E0038 message will be printed
984
+ match terr {
985
+ TypeError :: ObjectUnsafeCoercion ( _) => { }
986
+ _ => {
987
+ diag. span_label ( span, terr. to_string ( ) ) ;
988
+ if let Some ( ( sp, msg) ) = secondary_span {
989
+ diag. span_label ( sp, msg) ;
990
+ }
991
+ }
992
+ } ;
986
993
987
994
if let Some ( ( expected, found) ) = expected_found {
988
995
match ( terr, is_simple_error, expected == found) {
@@ -995,6 +1002,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
995
1002
& format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
996
1003
) ;
997
1004
}
1005
+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
1006
+ diag. note_unsuccessfull_coercion ( found, expected) ;
1007
+ }
998
1008
( _, false , _) => {
999
1009
if let Some ( exp_found) = exp_found {
1000
1010
let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1114,6 +1124,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1114
1124
let span = trace. cause . span ( & self . tcx ) ;
1115
1125
let failure_code = trace. cause . as_failure_code ( terr) ;
1116
1126
let mut diag = match failure_code {
1127
+ FailureCode :: Error0038 ( did) => {
1128
+ let violations = self . tcx . global_tcx ( )
1129
+ . object_safety_violations ( did) ;
1130
+ self . tcx . report_object_safety_error ( span, did, violations)
1131
+ }
1117
1132
FailureCode :: Error0317 ( failure_str) => {
1118
1133
struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
1119
1134
}
@@ -1471,6 +1486,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1471
1486
}
1472
1487
1473
1488
enum FailureCode {
1489
+ Error0038 ( DefId ) ,
1474
1490
Error0317 ( & ' static str ) ,
1475
1491
Error0580 ( & ' static str ) ,
1476
1492
Error0308 ( & ' static str ) ,
@@ -1504,6 +1520,7 @@ impl<'tcx> ObligationCause<'tcx> {
1504
1520
TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
1505
1521
Error0644 ( "closure/generator type that references itself" )
1506
1522
}
1523
+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
1507
1524
_ => Error0308 ( "mismatched types" ) ,
1508
1525
} ,
1509
1526
}
0 commit comments