@@ -1588,7 +1588,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1588
1588
& infcx_
1589
1589
} ;
1590
1590
1591
- tcx. all_traits ( )
1591
+ tcx. all_traits_including_private ( )
1592
1592
. filter ( |trait_def_id| {
1593
1593
// Consider only traits with the associated type
1594
1594
tcx. associated_items ( * trait_def_id)
@@ -2459,13 +2459,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2459
2459
// type a projection.
2460
2460
let in_trait = match opaque_ty. origin {
2461
2461
hir:: OpaqueTyOrigin :: FnReturn {
2462
+ parent,
2462
2463
in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
2463
2464
..
2464
2465
}
2465
2466
| hir:: OpaqueTyOrigin :: AsyncFn {
2467
+ parent,
2466
2468
in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
2467
2469
..
2468
- } => true ,
2470
+ } => Some ( parent ) ,
2469
2471
hir:: OpaqueTyOrigin :: FnReturn {
2470
2472
in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
2471
2473
..
@@ -2474,7 +2476,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2474
2476
in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
2475
2477
..
2476
2478
}
2477
- | hir:: OpaqueTyOrigin :: TyAlias { .. } => false ,
2479
+ | hir:: OpaqueTyOrigin :: TyAlias { .. } => None ,
2478
2480
} ;
2479
2481
2480
2482
self . lower_opaque_ty ( opaque_ty. def_id , in_trait)
@@ -2594,17 +2596,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2594
2596
2595
2597
/// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
2596
2598
#[ instrument( level = "debug" , skip( self ) , ret) ]
2597
- fn lower_opaque_ty ( & self , def_id : LocalDefId , in_trait : bool ) -> Ty < ' tcx > {
2599
+ fn lower_opaque_ty ( & self , def_id : LocalDefId , in_trait : Option < LocalDefId > ) -> Ty < ' tcx > {
2598
2600
let tcx = self . tcx ( ) ;
2599
2601
2600
2602
let lifetimes = tcx. opaque_captured_lifetimes ( def_id) ;
2601
2603
debug ! ( ?lifetimes) ;
2602
2604
2603
- // If this is an RPITIT and we are using the new RPITIT lowering scheme, we
2604
- // generate the def_id of an associated type for the trait and return as
2605
- // type a projection.
2606
- let def_id = if in_trait {
2607
- tcx. associated_type_for_impl_trait_in_trait ( def_id) . to_def_id ( )
2605
+ // If this is an RPITIT and we are using the new RPITIT lowering scheme,
2606
+ // do a linear search to map this to the synthetic associated type that
2607
+ // it will be lowered to.
2608
+ let def_id = if let Some ( parent_def_id) = in_trait {
2609
+ * tcx. associated_types_for_impl_traits_in_associated_fn ( parent_def_id)
2610
+ . iter ( )
2611
+ . find ( |rpitit| match tcx. opt_rpitit_info ( * * rpitit) {
2612
+ Some ( ty:: ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) => {
2613
+ opaque_def_id. expect_local ( ) == def_id
2614
+ }
2615
+ _ => unreachable ! ( ) ,
2616
+ } )
2617
+ . unwrap ( )
2608
2618
} else {
2609
2619
def_id. to_def_id ( )
2610
2620
} ;
@@ -2627,7 +2637,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2627
2637
} ) ;
2628
2638
debug ! ( ?args) ;
2629
2639
2630
- if in_trait {
2640
+ if in_trait. is_some ( ) {
2631
2641
Ty :: new_projection_from_args ( tcx, def_id, args)
2632
2642
} else {
2633
2643
Ty :: new_opaque ( tcx, def_id, args)
0 commit comments