@@ -960,10 +960,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
960
960
961
961
let span = cause. span ( & self . tcx ) ;
962
962
963
- diag. span_label ( span, terr. to_string ( ) ) ;
964
- if let Some ( ( sp, msg) ) = secondary_span {
965
- diag. span_label ( sp, msg) ;
966
- }
963
+ // Ignore msg for object safe coercion
964
+ // since E0038 message will be printed
965
+ match terr {
966
+ TypeError :: ObjectUnsafeCoercion ( _) => { }
967
+ _ => {
968
+ diag. span_label ( span, terr. to_string ( ) ) ;
969
+ if let Some ( ( sp, msg) ) = secondary_span {
970
+ diag. span_label ( sp, msg) ;
971
+ }
972
+ }
973
+ } ;
967
974
968
975
if let Some ( ( expected, found) ) = expected_found {
969
976
match ( terr, is_simple_error, expected == found) {
@@ -976,6 +983,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
976
983
& format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
977
984
) ;
978
985
}
986
+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
987
+ diag. note_unsuccessfull_coercion ( found, expected) ;
988
+ }
979
989
( _, false , _) => {
980
990
if let Some ( exp_found) = exp_found {
981
991
let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1095,6 +1105,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1095
1105
let span = trace. cause . span ( & self . tcx ) ;
1096
1106
let failure_code = trace. cause . as_failure_code ( terr) ;
1097
1107
let mut diag = match failure_code {
1108
+ FailureCode :: Error0038 ( did) => {
1109
+ let violations = self . tcx . global_tcx ( )
1110
+ . object_safety_violations ( did) ;
1111
+ self . tcx . report_object_safety_error ( span, did, violations)
1112
+ }
1098
1113
FailureCode :: Error0317 ( failure_str) => {
1099
1114
struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
1100
1115
}
@@ -1453,6 +1468,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1453
1468
}
1454
1469
1455
1470
enum FailureCode {
1471
+ Error0038 ( DefId ) ,
1456
1472
Error0317 ( & ' static str ) ,
1457
1473
Error0580 ( & ' static str ) ,
1458
1474
Error0308 ( & ' static str ) ,
@@ -1486,6 +1502,7 @@ impl<'tcx> ObligationCause<'tcx> {
1486
1502
TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
1487
1503
Error0644 ( "closure/generator type that references itself" )
1488
1504
}
1505
+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
1489
1506
_ => Error0308 ( "mismatched types" ) ,
1490
1507
} ,
1491
1508
}
0 commit comments