@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
33use rustc_hir as hir;
44use rustc_infer:: traits:: util;
55use rustc_middle:: ty:: subst:: InternalSubsts ;
6- use rustc_middle:: ty:: { self , ImplTraitInTraitData , Ty , TyCtxt } ;
6+ use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
77use rustc_span:: def_id:: DefId ;
88use rustc_span:: Span ;
99
@@ -76,18 +76,26 @@ pub(super) fn explicit_item_bounds(
7676 tcx : TyCtxt < ' _ > ,
7777 def_id : DefId ,
7878) -> & ' _ [ ( ty:: Predicate < ' _ > , Span ) ] {
79- // If the def_id is about an RPITIT, delegate explicit_item_bounds to the opaque_def_id that
80- // generated the synthesized associate type.
81- let rpitit_info = if let Some ( ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) =
82- tcx. opt_rpitit_info ( def_id)
83- {
84- Some ( opaque_def_id)
85- } else {
86- None
87- } ;
79+ match tcx. opt_rpitit_info ( def_id) {
80+ // RPITIT's bounds are the same as opaque type bounds, but with
81+ // a projection self type.
82+ Some ( ty:: ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) => {
83+ let item = tcx. hir ( ) . get_by_def_id ( opaque_def_id. expect_local ( ) ) . expect_item ( ) ;
84+ let opaque_ty = item. expect_opaque_ty ( ) ;
85+ return opaque_type_bounds (
86+ tcx,
87+ opaque_def_id,
88+ opaque_ty. bounds ,
89+ tcx. mk_projection ( def_id, ty:: InternalSubsts :: identity_for_item ( tcx, def_id) ) ,
90+ item. span ,
91+ ) ;
92+ }
93+ // These should have been fed!
94+ Some ( ty:: ImplTraitInTraitData :: Impl { .. } ) => unreachable ! ( ) ,
95+ None => { }
96+ }
8897
89- let bounds_def_id = rpitit_info. unwrap_or ( def_id) ;
90- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( bounds_def_id. expect_local ( ) ) ;
98+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
9199 match tcx. hir ( ) . get ( hir_id) {
92100 hir:: Node :: TraitItem ( hir:: TraitItem {
93101 kind : hir:: TraitItemKind :: Type ( bounds, _) ,
@@ -100,12 +108,12 @@ pub(super) fn explicit_item_bounds(
100108 ..
101109 } ) => {
102110 let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
103- let item_ty = if * in_trait || rpitit_info . is_some ( ) {
111+ let item_ty = if * in_trait && !tcx . lower_impl_trait_in_trait_to_assoc_ty ( ) {
104112 tcx. mk_projection ( def_id, substs)
105113 } else {
106114 tcx. mk_opaque ( def_id, substs)
107115 } ;
108- opaque_type_bounds ( tcx, bounds_def_id , bounds, item_ty, * span)
116+ opaque_type_bounds ( tcx, def_id , bounds, item_ty, * span)
109117 }
110118 _ => bug ! ( "item_bounds called on {:?}" , def_id) ,
111119 }
0 commit comments