@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
3
3
use rustc_hir as hir;
4
4
use rustc_infer:: traits:: util;
5
5
use rustc_middle:: ty:: subst:: InternalSubsts ;
6
- use rustc_middle:: ty:: { self , ImplTraitInTraitData , Ty , TyCtxt } ;
6
+ use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
7
7
use rustc_span:: def_id:: DefId ;
8
8
use rustc_span:: Span ;
9
9
@@ -76,18 +76,26 @@ pub(super) fn explicit_item_bounds(
76
76
tcx : TyCtxt < ' _ > ,
77
77
def_id : DefId ,
78
78
) -> & ' _ [ ( 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
+ }
88
97
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 ( ) ) ;
91
99
match tcx. hir ( ) . get ( hir_id) {
92
100
hir:: Node :: TraitItem ( hir:: TraitItem {
93
101
kind : hir:: TraitItemKind :: Type ( bounds, _) ,
@@ -100,12 +108,12 @@ pub(super) fn explicit_item_bounds(
100
108
..
101
109
} ) => {
102
110
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 ( ) {
104
112
tcx. mk_projection ( def_id, substs)
105
113
} else {
106
114
tcx. mk_opaque ( def_id, substs)
107
115
} ;
108
- opaque_type_bounds ( tcx, bounds_def_id , bounds, item_ty, * span)
116
+ opaque_type_bounds ( tcx, def_id , bounds, item_ty, * span)
109
117
}
110
118
_ => bug ! ( "item_bounds called on {:?}" , def_id) ,
111
119
}
0 commit comments