@@ -960,10 +960,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
960960
961961 let span = cause. span ( & self . tcx ) ;
962962
963- diag. span_label ( span, terr. to_string ( ) ) ;
964- if let Some ( ( sp, msg) ) = secondary_span {
965- diag. span_label ( sp, msg) ;
966- }
963+ // Ignore msg for object safe coercion
964+ // since E0038 message will be printed
965+ match terr {
966+ TypeError :: ObjectUnsafeCoercion ( _) => { }
967+ _ => {
968+ diag. span_label ( span, terr. to_string ( ) ) ;
969+ if let Some ( ( sp, msg) ) = secondary_span {
970+ diag. span_label ( sp, msg) ;
971+ }
972+ }
973+ } ;
967974
968975 if let Some ( ( expected, found) ) = expected_found {
969976 match ( terr, is_simple_error, expected == found) {
@@ -976,6 +983,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
976983 & format ! ( " ({})" , values. found. sort_string( self . tcx) ) ,
977984 ) ;
978985 }
986+ ( TypeError :: ObjectUnsafeCoercion ( _) , ..) => {
987+ diag. note_unsuccessfull_coercion ( found, expected) ;
988+ }
979989 ( _, false , _) => {
980990 if let Some ( exp_found) = exp_found {
981991 let ( def_id, ret_ty) = match exp_found. found . sty {
@@ -1095,6 +1105,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10951105 let span = trace. cause . span ( & self . tcx ) ;
10961106 let failure_code = trace. cause . as_failure_code ( terr) ;
10971107 let mut diag = match failure_code {
1108+ FailureCode :: Error0038 ( did) => {
1109+ let violations = self . tcx . global_tcx ( )
1110+ . object_safety_violations ( did) ;
1111+ self . tcx . report_object_safety_error ( span, did, violations)
1112+ }
10981113 FailureCode :: Error0317 ( failure_str) => {
10991114 struct_span_err ! ( self . tcx. sess, span, E0317 , "{}" , failure_str)
11001115 }
@@ -1453,6 +1468,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14531468}
14541469
14551470enum FailureCode {
1471+ Error0038 ( DefId ) ,
14561472 Error0317 ( & ' static str ) ,
14571473 Error0580 ( & ' static str ) ,
14581474 Error0308 ( & ' static str ) ,
@@ -1486,6 +1502,7 @@ impl<'tcx> ObligationCause<'tcx> {
14861502 TypeError :: CyclicTy ( ty) if ty. is_closure ( ) || ty. is_generator ( ) => {
14871503 Error0644 ( "closure/generator type that references itself" )
14881504 }
1505+ TypeError :: ObjectUnsafeCoercion ( did) => Error0038 ( did. clone ( ) ) ,
14891506 _ => Error0308 ( "mismatched types" ) ,
14901507 } ,
14911508 }
0 commit comments