@@ -10,6 +10,7 @@ use rustc_span::Span;
10
10
use rustc_type_ir:: Upcast ;
11
11
use tracing:: { debug, instrument} ;
12
12
13
+ use super :: predicates_of:: assert_only_contains_predicates_from;
13
14
use super :: ItemCtxt ;
14
15
use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter } ;
15
16
@@ -56,6 +57,9 @@ fn associated_type_bounds<'tcx>(
56
57
tcx. def_path_str( assoc_item_def_id. to_def_id( ) ) ,
57
58
all_bounds
58
59
) ;
60
+
61
+ assert_only_contains_predicates_from ( filter, all_bounds, item_ty) ;
62
+
59
63
all_bounds
60
64
}
61
65
@@ -108,18 +112,21 @@ pub(super) fn explicit_item_bounds_with_filter(
108
112
Some ( ty:: ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) => {
109
113
let item = tcx. hir_node_by_def_id ( opaque_def_id. expect_local ( ) ) . expect_item ( ) ;
110
114
let opaque_ty = item. expect_opaque_ty ( ) ;
111
- return ty:: EarlyBinder :: bind ( opaque_type_bounds (
115
+ let item_ty = Ty :: new_projection_from_args (
116
+ tcx,
117
+ def_id. to_def_id ( ) ,
118
+ ty:: GenericArgs :: identity_for_item ( tcx, def_id) ,
119
+ ) ;
120
+ let bounds = opaque_type_bounds (
112
121
tcx,
113
122
opaque_def_id. expect_local ( ) ,
114
123
opaque_ty. bounds ,
115
- Ty :: new_projection_from_args (
116
- tcx,
117
- def_id. to_def_id ( ) ,
118
- ty:: GenericArgs :: identity_for_item ( tcx, def_id) ,
119
- ) ,
124
+ item_ty,
120
125
item. span ,
121
126
filter,
122
- ) ) ;
127
+ ) ;
128
+ assert_only_contains_predicates_from ( filter, bounds, item_ty) ;
129
+ return ty:: EarlyBinder :: bind ( bounds) ;
123
130
}
124
131
Some ( ty:: ImplTraitInTraitData :: Impl { .. } ) => span_bug ! (
125
132
tcx. def_span( def_id) ,
@@ -167,7 +174,9 @@ pub(super) fn explicit_item_bounds_with_filter(
167
174
} ) => {
168
175
let args = GenericArgs :: identity_for_item ( tcx, def_id) ;
169
176
let item_ty = Ty :: new_opaque ( tcx, def_id. to_def_id ( ) , args) ;
170
- opaque_type_bounds ( tcx, def_id, bounds, item_ty, * span, filter)
177
+ let bounds = opaque_type_bounds ( tcx, def_id, bounds, item_ty, * span, filter) ;
178
+ assert_only_contains_predicates_from ( filter, bounds, item_ty) ;
179
+ bounds
171
180
}
172
181
// Since RPITITs are lowered as projections in `<dyn HirTyLowerer>::lower_ty`, when we're
173
182
// asking for the item bounds of the *opaques* in a trait's default method signature, we
@@ -184,15 +193,18 @@ pub(super) fn explicit_item_bounds_with_filter(
184
193
} ;
185
194
let args = GenericArgs :: identity_for_item ( tcx, def_id) ;
186
195
let item_ty = Ty :: new_opaque ( tcx, def_id. to_def_id ( ) , args) ;
187
- tcx. arena . alloc_slice (
196
+ let bounds = & * tcx. arena . alloc_slice (
188
197
& opaque_type_bounds ( tcx, def_id, bounds, item_ty, * span, filter)
189
198
. to_vec ( )
190
199
. fold_with ( & mut AssocTyToOpaque { tcx, fn_def_id : fn_def_id. to_def_id ( ) } ) ,
191
- )
200
+ ) ;
201
+ assert_only_contains_predicates_from ( filter, bounds, item_ty) ;
202
+ bounds
192
203
}
193
204
hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: TyAlias ( ..) , .. } ) => & [ ] ,
194
205
_ => bug ! ( "item_bounds called on {:?}" , def_id) ,
195
206
} ;
207
+
196
208
ty:: EarlyBinder :: bind ( bounds)
197
209
}
198
210
0 commit comments