@@ -20,7 +20,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
20
20
use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
21
21
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
22
22
use rustc_infer:: infer:: {
23
- BoundRegion , BoundRegionConversionTime , InferCtxt , NllRegionVariableOrigin ,
23
+ BoundRegion , BoundRegionConversionTime , DefineOpaqueTypes , InferCtxt , NllRegionVariableOrigin ,
24
24
} ;
25
25
use rustc_middle:: mir:: tcx:: PlaceTy ;
26
26
use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
@@ -2294,7 +2294,34 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2294
2294
let cast_ty_from = CastTy :: from_ty ( ty_from) ;
2295
2295
let cast_ty_to = CastTy :: from_ty ( * ty) ;
2296
2296
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
+ }
2298
2325
_ => {
2299
2326
span_mirbug ! (
2300
2327
self ,
0 commit comments