@@ -977,10 +977,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
977977
978978 let span = cause. span ( & self . tcx ) ;
979979
980- diag. span_label ( span, terr. to_string ( ) ) ;
981- if let Some ( ( sp, msg) ) = secondary_span {
982- diag. span_label ( sp, msg) ;
983- }
980+ // Ignore msg for object safe coercion
981+ // since E0038 message will be printed
982+ match terr {
983+ TypeError :: ObjectUnsafeCoercion ( _) => { }
984+ _ => {
985+ diag. span_label ( span, terr. to_string ( ) ) ;
986+ if let Some ( ( sp, msg) ) = secondary_span {
987+ diag. span_label ( sp, msg) ;
988+ }
989+ }
990+ } ;
984991
985992 if let Some ( ( expected, found) ) = expected_found {
986993 match ( terr, is_simple_error, expected == found) {
@@ -993,6 +1000,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9931000 & format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
9941001 ) ;
9951002 }
1003+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
1004+ diag. note_unsuccessfull_coercion ( found, expected) ;
1005+ }
9961006 ( _, false , _) => {
9971007 if let Some ( exp_found) = exp_found {
9981008 let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1112,6 +1122,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11121122 let span = trace. cause . span ( & self . tcx ) ;
11131123 let failure_code = trace. cause . as_failure_code ( terr) ;
11141124 let mut diag = match failure_code {
1125+ FailureCode :: Error0038 ( did) => {
1126+ let violations = self . tcx . global_tcx ( )
1127+ . object_safety_violations ( did) ;
1128+ self . tcx . report_object_safety_error ( span, did, violations)
1129+ }
11151130 FailureCode :: Error0317 ( failure_str) => {
11161131 struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
11171132 }
@@ -1470,6 +1485,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14701485}
14711486
14721487enum FailureCode {
1488+ Error0038 ( DefId ) ,
14731489 Error0317 ( & ' static str ) ,
14741490 Error0580 ( & ' static str ) ,
14751491 Error0308 ( & ' static str ) ,
@@ -1503,6 +1519,7 @@ impl<'tcx> ObligationCause<'tcx> {
15031519 TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
15041520 Error0644 ( "closure/generator type that references itself" )
15051521 }
1522+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
15061523 _ => Error0308 ( "mismatched types" ) ,
15071524 } ,
15081525 }
0 commit comments