@@ -1146,10 +1146,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1146
1146
1147
1147
let span = cause. span ( self . tcx ) ;
1148
1148
1149
- diag. span_label ( span, terr. to_string ( ) ) ;
1150
- if let Some ( ( sp, msg) ) = secondary_span {
1151
- diag. span_label ( sp, msg) ;
1152
- }
1149
+ // Ignore msg for object safe coercion
1150
+ // since E0038 message will be printed
1151
+ match terr {
1152
+ TypeError :: ObjectUnsafeCoercion ( _) => { }
1153
+ _ => {
1154
+ diag. span_label ( span, terr. to_string ( ) ) ;
1155
+ if let Some ( ( sp, msg) ) = secondary_span {
1156
+ diag. span_label ( sp, msg) ;
1157
+ }
1158
+ }
1159
+ } ;
1153
1160
1154
1161
if let Some ( ( expected, found) ) = expected_found {
1155
1162
match ( terr, is_simple_error, expected == found) {
@@ -1169,6 +1176,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1169
1176
& sort_string ( values. found ) ,
1170
1177
) ;
1171
1178
}
1179
+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
1180
+ diag. note_unsuccessfull_coercion ( found, expected) ;
1181
+ }
1172
1182
( _, false , _) => {
1173
1183
if let Some ( exp_found) = exp_found {
1174
1184
self . suggest_as_ref_where_appropriate ( span, & exp_found, diag) ;
@@ -1267,6 +1277,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1267
1277
let span = trace. cause . span ( self . tcx ) ;
1268
1278
let failure_code = trace. cause . as_failure_code ( terr) ;
1269
1279
let mut diag = match failure_code {
1280
+ FailureCode :: Error0038 ( did) => {
1281
+ let violations = self . tcx . object_safety_violations ( did) ;
1282
+ self . tcx . report_object_safety_error ( span, did, violations)
1283
+ }
1270
1284
FailureCode :: Error0317 ( failure_str) => {
1271
1285
struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
1272
1286
}
@@ -1628,6 +1642,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1628
1642
}
1629
1643
1630
1644
enum FailureCode {
1645
+ Error0038 ( DefId ) ,
1631
1646
Error0317 ( & ' static str ) ,
1632
1647
Error0580 ( & ' static str ) ,
1633
1648
Error0308 ( & ' static str ) ,
@@ -1666,6 +1681,7 @@ impl<'tcx> ObligationCause<'tcx> {
1666
1681
TypeError :: IntrinsicCast => {
1667
1682
Error0308 ( "cannot coerce intrinsics to function pointers" )
1668
1683
}
1684
+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
1669
1685
_ => Error0308 ( "mismatched types" ) ,
1670
1686
} ,
1671
1687
}
0 commit comments