@@ -10,6 +10,7 @@ use rustc_span::Span;
1010use rustc_type_ir:: Upcast ;
1111use tracing:: { debug, instrument} ;
1212
13+ use super :: predicates_of:: assert_only_contains_predicates_from;
1314use super :: ItemCtxt ;
1415use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter } ;
1516
@@ -56,6 +57,9 @@ fn associated_type_bounds<'tcx>(
5657 tcx. def_path_str( assoc_item_def_id. to_def_id( ) ) ,
5758 all_bounds
5859 ) ;
60+
61+ assert_only_contains_predicates_from ( filter, all_bounds, item_ty) ;
62+
5963 all_bounds
6064}
6165
@@ -108,18 +112,21 @@ pub(super) fn explicit_item_bounds_with_filter(
108112 Some ( ty:: ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) => {
109113 let item = tcx. hir_node_by_def_id ( opaque_def_id. expect_local ( ) ) . expect_item ( ) ;
110114 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 (
112121 tcx,
113122 opaque_def_id. expect_local ( ) ,
114123 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,
120125 item. span ,
121126 filter,
122- ) ) ;
127+ ) ;
128+ assert_only_contains_predicates_from ( filter, bounds, item_ty) ;
129+ return ty:: EarlyBinder :: bind ( bounds) ;
123130 }
124131 Some ( ty:: ImplTraitInTraitData :: Impl { .. } ) => span_bug ! (
125132 tcx. def_span( def_id) ,
@@ -167,7 +174,9 @@ pub(super) fn explicit_item_bounds_with_filter(
167174 } ) => {
168175 let args = GenericArgs :: identity_for_item ( tcx, def_id) ;
169176 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
171180 }
172181 // Since RPITITs are lowered as projections in `<dyn HirTyLowerer>::lower_ty`, when we're
173182 // 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(
184193 } ;
185194 let args = GenericArgs :: identity_for_item ( tcx, def_id) ;
186195 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 (
188197 & opaque_type_bounds ( tcx, def_id, bounds, item_ty, * span, filter)
189198 . to_vec ( )
190199 . 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
192203 }
193204 hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: TyAlias ( ..) , .. } ) => & [ ] ,
194205 _ => bug ! ( "item_bounds called on {:?}" , def_id) ,
195206 } ;
207+
196208 ty:: EarlyBinder :: bind ( bounds)
197209}
198210
0 commit comments