@@ -1146,10 +1146,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11461146
11471147 let span = cause. span ( self . tcx ) ;
11481148
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+ } ;
11531160
11541161 if let Some ( ( expected, found) ) = expected_found {
11551162 match ( terr, is_simple_error, expected == found) {
@@ -1169,6 +1176,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11691176 & sort_string ( values. found ) ,
11701177 ) ;
11711178 }
1179+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
1180+ diag. note_unsuccessfull_coercion ( found, expected) ;
1181+ }
11721182 ( _, false , _) => {
11731183 if let Some ( exp_found) = exp_found {
11741184 self . suggest_as_ref_where_appropriate ( span, & exp_found, diag) ;
@@ -1267,6 +1277,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12671277 let span = trace. cause . span ( self . tcx ) ;
12681278 let failure_code = trace. cause . as_failure_code ( terr) ;
12691279 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+ }
12701284 FailureCode :: Error0317 ( failure_str) => {
12711285 struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
12721286 }
@@ -1628,6 +1642,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16281642}
16291643
16301644enum FailureCode {
1645+ Error0038 ( DefId ) ,
16311646 Error0317 ( & ' static str ) ,
16321647 Error0580 ( & ' static str ) ,
16331648 Error0308 ( & ' static str ) ,
@@ -1666,6 +1681,7 @@ impl<'tcx> ObligationCause<'tcx> {
16661681 TypeError :: IntrinsicCast => {
16671682 Error0308 ( "cannot coerce intrinsics to function pointers" )
16681683 }
1684+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
16691685 _ => Error0308 ( "mismatched types" ) ,
16701686 } ,
16711687 }
0 commit comments