@@ -943,10 +943,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
943943
944944 let span = cause. span ( & self . tcx ) ;
945945
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+ } ;
950957
951958 if let Some ( ( expected, found) ) = expected_found {
952959 match ( terr, is_simple_error, expected == found) {
@@ -959,6 +966,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
959966 & format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
960967 ) ;
961968 }
969+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
970+ diag. note_unsuccessfull_coercion ( found, expected) ;
971+ }
962972 ( _, false , _) => {
963973 if let Some ( exp_found) = exp_found {
964974 let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1078,6 +1088,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10781088 let span = trace. cause . span ( & self . tcx ) ;
10791089 let failure_code = trace. cause . as_failure_code ( terr) ;
10801090 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+ }
10811096 FailureCode :: Error0317 ( failure_str) => {
10821097 struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
10831098 }
@@ -1436,6 +1451,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14361451}
14371452
14381453enum FailureCode {
1454+ Error0038 ( DefId ) ,
14391455 Error0317 ( & ' static str ) ,
14401456 Error0580 ( & ' static str ) ,
14411457 Error0308 ( & ' static str ) ,
@@ -1469,6 +1485,7 @@ impl<'tcx> ObligationCause<'tcx> {
14691485 TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
14701486 Error0644 ( "closure/generator type that references itself" )
14711487 }
1488+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
14721489 _ => Error0308 ( "mismatched types" ) ,
14731490 } ,
14741491 }
0 commit comments