@@ -564,7 +564,11 @@ pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
564
564
tcx : TyCtxt < ' tcx > ,
565
565
( trait_def_id, assoc_name) : ( DefId , Ident ) ,
566
566
) -> ty:: EarlyBinder < ' tcx , & ' tcx [ ( ty:: Clause < ' tcx > , Span ) ] > {
567
- implied_predicates_with_filter ( tcx, trait_def_id, PredicateFilter :: SelfThatDefines ( assoc_name) )
567
+ implied_predicates_with_filter (
568
+ tcx,
569
+ trait_def_id,
570
+ PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
571
+ )
568
572
}
569
573
570
574
pub ( super ) fn explicit_implied_predicates_of < ' tcx > (
@@ -593,7 +597,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
593
597
let Some ( trait_def_id) = trait_def_id. as_local ( ) else {
594
598
// if `assoc_name` is None, then the query should've been redirected to an
595
599
// external provider
596
- assert_matches ! ( filter, PredicateFilter :: SelfThatDefines ( _) ) ;
600
+ assert_matches ! ( filter, PredicateFilter :: SelfTraitThatDefines ( _) ) ;
597
601
return tcx. explicit_super_predicates_of ( trait_def_id) ;
598
602
} ;
599
603
@@ -667,7 +671,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
667
671
}
668
672
669
673
match filter {
670
- PredicateFilter :: SelfOnly | PredicateFilter :: SelfThatDefines ( _ ) => {
674
+ PredicateFilter :: SelfOnly => {
671
675
for ( clause, _) in bounds {
672
676
match clause. kind ( ) . skip_binder ( ) {
673
677
ty:: ClauseKind :: Trait ( trait_predicate) => {
@@ -707,6 +711,33 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
707
711
}
708
712
}
709
713
}
714
+ PredicateFilter :: SelfTraitThatDefines ( _) => {
715
+ for ( clause, _) in bounds {
716
+ match clause. kind ( ) . skip_binder ( ) {
717
+ ty:: ClauseKind :: Trait ( trait_predicate) => {
718
+ assert_eq ! (
719
+ trait_predicate. self_ty( ) ,
720
+ ty,
721
+ "expected `Self` predicate when computing \
722
+ `{filter:?}` implied bounds: {clause:?}"
723
+ ) ;
724
+ }
725
+
726
+ ty:: ClauseKind :: Projection ( _)
727
+ | ty:: ClauseKind :: TypeOutlives ( _)
728
+ | ty:: ClauseKind :: RegionOutlives ( _)
729
+ | ty:: ClauseKind :: ConstArgHasType ( _, _)
730
+ | ty:: ClauseKind :: WellFormed ( _)
731
+ | ty:: ClauseKind :: ConstEvaluatable ( _)
732
+ | ty:: ClauseKind :: HostEffect ( ..) => {
733
+ bug ! (
734
+ "unexpected non-`Self` predicate when computing \
735
+ `{filter:?}` implied bounds: {clause:?}"
736
+ ) ;
737
+ }
738
+ }
739
+ }
740
+ }
710
741
PredicateFilter :: ConstIfConst => {
711
742
for ( clause, _) in bounds {
712
743
match clause. kind ( ) . skip_binder ( ) {
@@ -768,11 +799,10 @@ pub(super) fn type_param_predicates<'tcx>(
768
799
769
800
let param_id = tcx. local_def_id_to_hir_id ( def_id) ;
770
801
let param_owner = tcx. hir ( ) . ty_param_owner ( def_id) ;
771
- let generics = tcx. generics_of ( param_owner) ;
772
- let index = generics. param_def_id_to_index [ & def_id. to_def_id ( ) ] ;
773
802
774
803
// Don't look for bounds where the type parameter isn't in scope.
775
804
let parent = if item_def_id == param_owner {
805
+ // FIXME: Shouldn't this be unreachable?
776
806
None
777
807
} else {
778
808
tcx. generics_of ( item_def_id) . parent . map ( |def_id| def_id. expect_local ( ) )
@@ -792,6 +822,7 @@ pub(super) fn type_param_predicates<'tcx>(
792
822
let Some ( hir_generics) = hir_node. generics ( ) else {
793
823
return result;
794
824
} ;
825
+
795
826
if let Node :: Item ( item) = hir_node
796
827
&& let ItemKind :: Trait ( ..) = item. kind
797
828
// Implied `Self: Trait` and supertrait bounds.
@@ -802,18 +833,11 @@ pub(super) fn type_param_predicates<'tcx>(
802
833
}
803
834
804
835
let icx = ItemCtxt :: new ( tcx, item_def_id) ;
805
- let extra_predicates = extend. into_iter ( ) . chain (
806
- icx. probe_ty_param_bounds_in_generics (
807
- hir_generics,
808
- def_id,
809
- PredicateFilter :: SelfThatDefines ( assoc_name) ,
810
- )
811
- . into_iter ( )
812
- . filter ( |( predicate, _) | match predicate. kind ( ) . skip_binder ( ) {
813
- ty:: ClauseKind :: Trait ( data) => data. self_ty ( ) . is_param ( index) ,
814
- _ => false ,
815
- } ) ,
816
- ) ;
836
+ let extra_predicates = extend. into_iter ( ) . chain ( icx. probe_ty_param_bounds_in_generics (
837
+ hir_generics,
838
+ def_id,
839
+ PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
840
+ ) ) ;
817
841
818
842
ty:: EarlyBinder :: bind (
819
843
tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) ,
@@ -848,7 +872,7 @@ impl<'tcx> ItemCtxt<'tcx> {
848
872
// Ok
849
873
}
850
874
PredicateFilter :: SelfOnly
851
- | PredicateFilter :: SelfThatDefines ( _)
875
+ | PredicateFilter :: SelfTraitThatDefines ( _)
852
876
| PredicateFilter :: SelfConstIfConst
853
877
| PredicateFilter :: SelfAndAssociatedTypeBounds => continue ,
854
878
PredicateFilter :: ConstIfConst => unreachable ! ( ) ,
0 commit comments