@@ -557,7 +557,11 @@ pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
557557tcx : TyCtxt < ' tcx > ,
558558( trait_def_id, assoc_name) : ( DefId , Ident ) ,
559559) -> ty:: EarlyBinder < ' tcx , & ' tcx [ ( ty:: Clause < ' tcx > , Span ) ] > {
560- implied_predicates_with_filter ( tcx, trait_def_id, PredicateFilter :: SelfThatDefines ( assoc_name) )
560+ implied_predicates_with_filter (
561+ tcx,
562+ trait_def_id,
563+ PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
564+ )
561565}
562566
563567pub ( super ) fn explicit_implied_predicates_of < ' tcx > (
@@ -586,7 +590,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
586590let Some ( trait_def_id) = trait_def_id. as_local ( ) else {
587591// if `assoc_name` is None, then the query should've been redirected to an
588592// external provider
589- assert_matches ! ( filter, PredicateFilter :: SelfThatDefines ( _) ) ;
593+ assert_matches ! ( filter, PredicateFilter :: SelfTraitThatDefines ( _) ) ;
590594return tcx. explicit_super_predicates_of ( trait_def_id) ;
591595} ;
592596
@@ -660,7 +664,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
660664}
661665
662666match filter {
663- PredicateFilter :: SelfOnly | PredicateFilter :: SelfThatDefines ( _ ) => {
667+ PredicateFilter :: SelfOnly => {
664668for ( clause, _) in bounds {
665669match clause. kind ( ) . skip_binder ( ) {
666670 ty:: ClauseKind :: Trait ( trait_predicate) => {
@@ -700,6 +704,33 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
700704}
701705}
702706}
707+ PredicateFilter :: SelfTraitThatDefines ( _) => {
708+ for ( clause, _) in bounds {
709+ match clause. kind ( ) . skip_binder ( ) {
710+ ty:: ClauseKind :: Trait ( trait_predicate) => {
711+ assert_eq ! (
712+ trait_predicate. self_ty( ) ,
713+ ty,
714+ "expected `Self` predicate when computing \
715+ `{filter:?}` implied bounds: {clause:?}"
716+ ) ;
717+ }
718+
719+ ty:: ClauseKind :: Projection ( _)
720+ | ty:: ClauseKind :: TypeOutlives ( _)
721+ | ty:: ClauseKind :: RegionOutlives ( _)
722+ | ty:: ClauseKind :: ConstArgHasType ( _, _)
723+ | ty:: ClauseKind :: WellFormed ( _)
724+ | ty:: ClauseKind :: ConstEvaluatable ( _)
725+ | ty:: ClauseKind :: HostEffect ( ..) => {
726+ bug ! (
727+ "unexpected non-`Self` predicate when computing \
728+ `{filter:?}` implied bounds: {clause:?}"
729+ ) ;
730+ }
731+ }
732+ }
733+ }
703734PredicateFilter :: ConstIfConst => {
704735for ( clause, _) in bounds {
705736match clause. kind ( ) . skip_binder ( ) {
@@ -771,11 +802,10 @@ pub(super) fn type_param_predicates<'tcx>(
771802
772803let param_id = tcx. local_def_id_to_hir_id ( def_id) ;
773804let param_owner = tcx. hir ( ) . ty_param_owner ( def_id) ;
774- let generics = tcx. generics_of ( param_owner) ;
775- let index = generics. param_def_id_to_index [ & def_id. to_def_id ( ) ] ;
776805
777806// Don't look for bounds where the type parameter isn't in scope.
778807let parent = if item_def_id == param_owner {
808+ // FIXME: Shouldn't this be unreachable?
779809None
780810} else {
781811 tcx. generics_of ( item_def_id) . parent . map ( |def_id| def_id. expect_local ( ) )
@@ -795,6 +825,7 @@ pub(super) fn type_param_predicates<'tcx>(
795825let Some ( hir_generics) = hir_node. generics ( ) else {
796826return result;
797827} ;
828+
798829if let Node :: Item ( item) = hir_node
799830 && let ItemKind :: Trait ( ..) = item. kind
800831// Implied `Self: Trait` and supertrait bounds.
@@ -805,18 +836,11 @@ pub(super) fn type_param_predicates<'tcx>(
805836}
806837
807838let icx = ItemCtxt :: new ( tcx, item_def_id) ;
808- let extra_predicates = extend. into_iter ( ) . chain (
809- icx. probe_ty_param_bounds_in_generics (
810- hir_generics,
811- def_id,
812- PredicateFilter :: SelfThatDefines ( assoc_name) ,
813- )
814- . into_iter ( )
815- . filter ( |( predicate, _) | match predicate. kind ( ) . skip_binder ( ) {
816- ty:: ClauseKind :: Trait ( data) => data. self_ty ( ) . is_param ( index) ,
817- _ => false ,
818- } ) ,
819- ) ;
839+ let extra_predicates = extend. into_iter ( ) . chain ( icx. probe_ty_param_bounds_in_generics (
840+ hir_generics,
841+ def_id,
842+ PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
843+ ) ) ;
820844
821845 ty:: EarlyBinder :: bind (
822846 tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) ,
@@ -851,7 +875,7 @@ impl<'tcx> ItemCtxt<'tcx> {
851875// Ok
852876}
853877PredicateFilter :: SelfOnly
854- | PredicateFilter :: SelfThatDefines ( _)
878+ | PredicateFilter :: SelfTraitThatDefines ( _)
855879 | PredicateFilter :: SelfConstIfConst
856880 | PredicateFilter :: SelfAndAssociatedTypeBounds => continue ,
857881PredicateFilter :: ConstIfConst => unreachable ! ( ) ,
0 commit comments