@@ -20,7 +20,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
2020use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
2121use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
2222use rustc_infer:: infer:: {
23- BoundRegion , BoundRegionConversionTime , InferCtxt , NllRegionVariableOrigin ,
23+ BoundRegion , BoundRegionConversionTime , DefineOpaqueTypes , InferCtxt , NllRegionVariableOrigin ,
2424} ;
2525use rustc_middle:: mir:: tcx:: PlaceTy ;
2626use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
@@ -2294,7 +2294,34 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22942294 let cast_ty_from = CastTy :: from_ty ( ty_from) ;
22952295 let cast_ty_to = CastTy :: from_ty ( * ty) ;
22962296 match ( cast_ty_from, cast_ty_to) {
2297- ( Some ( CastTy :: Ptr ( _) ) , Some ( CastTy :: Ptr ( _) ) ) => ( ) ,
2297+ ( Some ( CastTy :: Ptr ( from_pointee) ) , Some ( CastTy :: Ptr ( to_pointee) ) ) => {
2298+ if let ty:: Dynamic ( to_preds, _, ty:: Dyn ) = * to_pointee. ty . kind ( )
2299+ && let Some ( to_principal) = to_preds. principal ( )
2300+ && let ty:: Dynamic ( from_preds, _, ty:: Dyn ) =
2301+ * from_pointee. ty . kind ( )
2302+ && let Some ( from_principal) = from_preds. principal ( )
2303+ {
2304+ let param_env = self . param_env ;
2305+ let op = CustomTypeOp :: new (
2306+ |ocx| {
2307+ let cause = ObligationCause :: dummy_with_span ( span) ;
2308+ let infer_ok = ocx. infcx . at ( & cause, param_env) . eq (
2309+ DefineOpaqueTypes :: No ,
2310+ from_principal,
2311+ to_principal,
2312+ ) ?;
2313+ ocx. register_infer_ok_obligations ( infer_ok) ;
2314+ Ok ( ( ) )
2315+ } ,
2316+ "equate PtrToPtr dyn trait principal" ,
2317+ ) ;
2318+ let _: Result < ( ) , ErrorGuaranteed > = self . fully_perform_op (
2319+ location. to_locations ( ) ,
2320+ ConstraintCategory :: Cast { unsize_to : None } ,
2321+ op,
2322+ ) ;
2323+ }
2324+ }
22982325 _ => {
22992326 span_mirbug ! (
23002327 self ,
0 commit comments