@@ -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 , TyCtxt } ;
6
+ use rustc_middle:: ty:: { self , ImplTraitInTraitData , Ty , TyCtxt } ;
7
7
use rustc_span:: def_id:: DefId ;
8
8
use rustc_span:: Span ;
9
9
@@ -58,17 +58,10 @@ fn opaque_type_bounds<'tcx>(
58
58
tcx : TyCtxt < ' tcx > ,
59
59
opaque_def_id : DefId ,
60
60
ast_bounds : & ' tcx [ hir:: GenericBound < ' tcx > ] ,
61
+ item_ty : Ty < ' tcx > ,
61
62
span : Span ,
62
- in_trait : bool ,
63
63
) -> & ' tcx [ ( ty:: Predicate < ' tcx > , Span ) ] {
64
64
ty:: print:: with_no_queries!( {
65
- let substs = InternalSubsts :: identity_for_item( tcx, opaque_def_id) ;
66
- let item_ty = if in_trait {
67
- tcx. mk_projection( opaque_def_id, substs)
68
- } else {
69
- tcx. mk_opaque( opaque_def_id, substs)
70
- } ;
71
-
72
65
let icx = ItemCtxt :: new( tcx, opaque_def_id) ;
73
66
let mut bounds = icx. astconv( ) . compute_bounds( item_ty, ast_bounds) ;
74
67
// Opaque types are implicitly sized unless a `?Sized` bound is found
@@ -83,7 +76,18 @@ pub(super) fn explicit_item_bounds(
83
76
tcx : TyCtxt < ' _ > ,
84
77
def_id : DefId ,
85
78
) -> & ' _ [ ( ty:: Predicate < ' _ > , Span ) ] {
86
- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
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
+ } ;
88
+
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 ( ) ) ;
87
91
match tcx. hir ( ) . get ( hir_id) {
88
92
hir:: Node :: TraitItem ( hir:: TraitItem {
89
93
kind : hir:: TraitItemKind :: Type ( bounds, _) ,
@@ -94,7 +98,15 @@ pub(super) fn explicit_item_bounds(
94
98
kind : hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds, in_trait, .. } ) ,
95
99
span,
96
100
..
97
- } ) => opaque_type_bounds ( tcx, def_id, bounds, * span, * in_trait) ,
101
+ } ) => {
102
+ let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
103
+ let item_ty = if * in_trait || rpitit_info. is_some ( ) {
104
+ tcx. mk_projection ( def_id, substs)
105
+ } else {
106
+ tcx. mk_opaque ( def_id, substs)
107
+ } ;
108
+ opaque_type_bounds ( tcx, bounds_def_id, bounds, item_ty, * span)
109
+ }
98
110
_ => bug ! ( "item_bounds called on {:?}" , def_id) ,
99
111
}
100
112
}
0 commit comments