@@ -755,20 +755,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
755755
756756 if let ty:: Dynamic ( a_data, _, _) = a. kind ( )
757757 && let ty:: Dynamic ( b_data, _, _) = b. kind ( )
758+ && a_data. principal_def_id ( ) == b_data. principal_def_id ( )
758759 {
759- if a_data. principal_def_id ( ) == b_data. principal_def_id ( ) {
760- return self . unify_and ( a, b, |_| vec ! [ ] ) ;
761- } else if !self . tcx ( ) . features ( ) . trait_upcasting {
762- let mut err = feature_err (
763- & self . tcx . sess . parse_sess ,
764- sym:: trait_upcasting,
765- self . cause . span ,
766- & format ! (
767- "cannot cast `{a}` to `{b}`, trait upcasting coercion is experimental"
768- ) ,
769- ) ;
770- err. emit ( ) ;
771- }
760+ return self . unify_and ( a, b, |_| vec ! [ ] ) ;
772761 }
773762
774763 // Check the obligations of the cast -- for example, when casting
@@ -796,19 +785,16 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
796785 ] )
797786 . collect ( ) ;
798787
799- // Enforce that the type is `usize`/pointer-sized. For now, only those
800- // can be coerced to `dyn*`, except for `dyn* -> dyn*` upcasts.
801- if !a. is_dyn_star ( ) {
802- obligations. push ( Obligation :: new (
803- self . tcx ,
804- self . cause . clone ( ) ,
805- self . param_env ,
806- ty:: Binder :: dummy (
807- self . tcx . at ( self . cause . span ) . mk_trait_ref ( hir:: LangItem :: PointerSized , [ a] ) ,
808- )
809- . to_poly_trait_predicate ( ) ,
810- ) ) ;
811- }
788+ // Enforce that the type is `usize`/pointer-sized.
789+ obligations. push ( Obligation :: new (
790+ self . tcx ,
791+ self . cause . clone ( ) ,
792+ self . param_env ,
793+ ty:: Binder :: dummy (
794+ self . tcx . at ( self . cause . span ) . mk_trait_ref ( hir:: LangItem :: PointerSized , [ a] ) ,
795+ )
796+ . to_poly_trait_predicate ( ) ,
797+ ) ) ;
812798
813799 Ok ( InferOk {
814800 value : ( vec ! [ Adjustment { kind: Adjust :: DynStar , target: b } ] , b) ,
0 commit comments