@@ -557,7 +557,11 @@ pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
557
557
tcx : TyCtxt < ' tcx > ,
558
558
( trait_def_id, assoc_name) : ( DefId , Ident ) ,
559
559
) -> 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
+ )
561
565
}
562
566
563
567
pub ( super ) fn explicit_implied_predicates_of < ' tcx > (
@@ -586,7 +590,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
586
590
let Some ( trait_def_id) = trait_def_id. as_local ( ) else {
587
591
// if `assoc_name` is None, then the query should've been redirected to an
588
592
// external provider
589
- assert_matches ! ( filter, PredicateFilter :: SelfThatDefines ( _) ) ;
593
+ assert_matches ! ( filter, PredicateFilter :: SelfTraitThatDefines ( _) ) ;
590
594
return tcx. explicit_super_predicates_of ( trait_def_id) ;
591
595
} ;
592
596
@@ -660,7 +664,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
660
664
}
661
665
662
666
match filter {
663
- PredicateFilter :: SelfOnly | PredicateFilter :: SelfThatDefines ( _ ) => {
667
+ PredicateFilter :: SelfOnly => {
664
668
for ( clause, _) in bounds {
665
669
match clause. kind ( ) . skip_binder ( ) {
666
670
ty:: ClauseKind :: Trait ( trait_predicate) => {
@@ -700,6 +704,33 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
700
704
}
701
705
}
702
706
}
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
+ }
703
734
PredicateFilter :: ConstIfConst => {
704
735
for ( clause, _) in bounds {
705
736
match clause. kind ( ) . skip_binder ( ) {
@@ -771,11 +802,10 @@ pub(super) fn type_param_predicates<'tcx>(
771
802
772
803
let param_id = tcx. local_def_id_to_hir_id ( def_id) ;
773
804
let 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 ( ) ] ;
776
805
777
806
// Don't look for bounds where the type parameter isn't in scope.
778
807
let parent = if item_def_id == param_owner {
808
+ // FIXME: Shouldn't this be unreachable?
779
809
None
780
810
} else {
781
811
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>(
795
825
let Some ( hir_generics) = hir_node. generics ( ) else {
796
826
return result;
797
827
} ;
828
+
798
829
if let Node :: Item ( item) = hir_node
799
830
&& let ItemKind :: Trait ( ..) = item. kind
800
831
// Implied `Self: Trait` and supertrait bounds.
@@ -805,18 +836,11 @@ pub(super) fn type_param_predicates<'tcx>(
805
836
}
806
837
807
838
let 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
+ ) ) ;
820
844
821
845
ty:: EarlyBinder :: bind (
822
846
tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) ,
@@ -851,7 +875,7 @@ impl<'tcx> ItemCtxt<'tcx> {
851
875
// Ok
852
876
}
853
877
PredicateFilter :: SelfOnly
854
- | PredicateFilter :: SelfThatDefines ( _)
878
+ | PredicateFilter :: SelfTraitThatDefines ( _)
855
879
| PredicateFilter :: SelfConstIfConst
856
880
| PredicateFilter :: SelfAndAssociatedTypeBounds => continue ,
857
881
PredicateFilter :: ConstIfConst => unreachable ! ( ) ,
0 commit comments