@@ -1588,7 +1588,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15881588 & infcx_
15891589 } ;
15901590
1591- tcx. all_traits ( )
1591+ tcx. all_traits_including_private ( )
15921592 . filter ( |trait_def_id| {
15931593 // Consider only traits with the associated type
15941594 tcx. associated_items ( * trait_def_id)
@@ -2459,13 +2459,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24592459 // type a projection.
24602460 let in_trait = match opaque_ty. origin {
24612461 hir:: OpaqueTyOrigin :: FnReturn {
2462+ parent,
24622463 in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
24632464 ..
24642465 }
24652466 | hir:: OpaqueTyOrigin :: AsyncFn {
2467+ parent,
24662468 in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
24672469 ..
2468- } => true ,
2470+ } => Some ( parent ) ,
24692471 hir:: OpaqueTyOrigin :: FnReturn {
24702472 in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
24712473 ..
@@ -2474,7 +2476,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24742476 in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
24752477 ..
24762478 }
2477- | hir:: OpaqueTyOrigin :: TyAlias { .. } => false ,
2479+ | hir:: OpaqueTyOrigin :: TyAlias { .. } => None ,
24782480 } ;
24792481
24802482 self . lower_opaque_ty ( opaque_ty. def_id , in_trait)
@@ -2594,17 +2596,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25942596
25952597 /// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
25962598 #[ 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 > {
25982600 let tcx = self . tcx ( ) ;
25992601
26002602 let lifetimes = tcx. opaque_captured_lifetimes ( def_id) ;
26012603 debug ! ( ?lifetimes) ;
26022604
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 ( )
26082618 } else {
26092619 def_id. to_def_id ( )
26102620 } ;
@@ -2627,7 +2637,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26272637 } ) ;
26282638 debug ! ( ?args) ;
26292639
2630- if in_trait {
2640+ if in_trait. is_some ( ) {
26312641 Ty :: new_projection_from_args ( tcx, def_id, args)
26322642 } else {
26332643 Ty :: new_opaque ( tcx, def_id, args)
0 commit comments