@@ -979,10 +979,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
979979
980980 let span = cause. span ( & self . tcx ) ;
981981
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+ } ;
986993
987994 if let Some ( ( expected, found) ) = expected_found {
988995 match ( terr, is_simple_error, expected == found) {
@@ -995,6 +1002,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9951002 & format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
9961003 ) ;
9971004 }
1005+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
1006+ diag. note_unsuccessfull_coercion ( found, expected) ;
1007+ }
9981008 ( _, false , _) => {
9991009 if let Some ( exp_found) = exp_found {
10001010 let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1114,6 +1124,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11141124 let span = trace. cause . span ( & self . tcx ) ;
11151125 let failure_code = trace. cause . as_failure_code ( terr) ;
11161126 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+ }
11171132 FailureCode :: Error0317 ( failure_str) => {
11181133 struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
11191134 }
@@ -1471,6 +1486,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14711486}
14721487
14731488enum FailureCode {
1489+ Error0038 ( DefId ) ,
14741490 Error0317 ( & ' static str ) ,
14751491 Error0580 ( & ' static str ) ,
14761492 Error0308 ( & ' static str ) ,
@@ -1504,6 +1520,7 @@ impl<'tcx> ObligationCause<'tcx> {
15041520 TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
15051521 Error0644 ( "closure/generator type that references itself" )
15061522 }
1523+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
15071524 _ => Error0308 ( "mismatched types" ) ,
15081525 } ,
15091526 }
0 commit comments