@@ -943,10 +943,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
943
943
944
944
let span = cause. span ( & self . tcx ) ;
945
945
946
- diag. span_label ( span, terr. to_string ( ) ) ;
947
- if let Some ( ( sp, msg) ) = secondary_span {
948
- diag. span_label ( sp, msg) ;
949
- }
946
+ // Ignore msg for object safe coercion
947
+ // since E0038 message will be printed
948
+ match terr {
949
+ TypeError :: ObjectUnsafeCoercion ( _) => { }
950
+ _ => {
951
+ diag. span_label ( span, terr. to_string ( ) ) ;
952
+ if let Some ( ( sp, msg) ) = secondary_span {
953
+ diag. span_label ( sp, msg) ;
954
+ }
955
+ }
956
+ } ;
950
957
951
958
if let Some ( ( expected, found) ) = expected_found {
952
959
match ( terr, is_simple_error, expected == found) {
@@ -959,6 +966,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
959
966
& format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
960
967
) ;
961
968
}
969
+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
970
+ diag. note_unsuccessfull_coercion ( found, expected) ;
971
+ }
962
972
( _, false , _) => {
963
973
if let Some ( exp_found) = exp_found {
964
974
let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1078,6 +1088,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1078
1088
let span = trace. cause . span ( & self . tcx ) ;
1079
1089
let failure_code = trace. cause . as_failure_code ( terr) ;
1080
1090
let mut diag = match failure_code {
1091
+ FailureCode :: Error0038 ( did) => {
1092
+ let violations = self . tcx . global_tcx ( )
1093
+ . object_safety_violations ( did) ;
1094
+ self . tcx . report_object_safety_error ( span, did, violations)
1095
+ }
1081
1096
FailureCode :: Error0317 ( failure_str) => {
1082
1097
struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
1083
1098
}
@@ -1436,6 +1451,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1436
1451
}
1437
1452
1438
1453
enum FailureCode {
1454
+ Error0038 ( DefId ) ,
1439
1455
Error0317 ( & ' static str ) ,
1440
1456
Error0580 ( & ' static str ) ,
1441
1457
Error0308 ( & ' static str ) ,
@@ -1469,6 +1485,7 @@ impl<'tcx> ObligationCause<'tcx> {
1469
1485
TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
1470
1486
Error0644 ( "closure/generator type that references itself" )
1471
1487
}
1488
+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
1472
1489
_ => Error0308 ( "mismatched types" ) ,
1473
1490
} ,
1474
1491
}
0 commit comments