@@ -652,7 +652,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
652
652
}
653
653
654
654
// Make sure when elaborating supertraits, probing for associated types, etc.,
655
- // we really truly are elaborating clauses that have `Self ` as their self type.
655
+ // we really truly are elaborating clauses that have `ty ` as their self type.
656
656
// This is very important since downstream code relies on this being correct.
657
657
pub ( super ) fn assert_only_contains_predicates_from < ' tcx > (
658
658
filter : PredicateFilter ,
@@ -794,8 +794,6 @@ pub(super) fn type_param_predicates<'tcx>(
794
794
None => { }
795
795
}
796
796
797
- use rustc_hir:: * ;
798
-
799
797
// In the HIR, bounds can derive from two places. Either
800
798
// written inline like `<T: Foo>` or in a where-clause like
801
799
// `where T: Foo`.
@@ -827,7 +825,7 @@ pub(super) fn type_param_predicates<'tcx>(
827
825
} ;
828
826
829
827
if let Node :: Item ( item) = hir_node
830
- && let ItemKind :: Trait ( ..) = item. kind
828
+ && let hir :: ItemKind :: Trait ( ..) = item. kind
831
829
// Implied `Self: Trait` and supertrait bounds.
832
830
&& param_id == item_hir_id
833
831
{
@@ -842,9 +840,28 @@ pub(super) fn type_param_predicates<'tcx>(
842
840
PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
843
841
) ) ;
844
842
845
- ty:: EarlyBinder :: bind (
846
- tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) ,
847
- )
843
+ let bounds =
844
+ & * tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) ;
845
+
846
+ // Double check that the bounds *only* contain `SelfTy: Trait` preds.
847
+ let self_ty = match tcx. def_kind ( def_id) {
848
+ DefKind :: TyParam => Ty :: new_param (
849
+ tcx,
850
+ tcx. generics_of ( item_def_id)
851
+ . param_def_id_to_index ( tcx, def_id. to_def_id ( ) )
852
+ . expect ( "expected generic param to be owned by item" ) ,
853
+ tcx. item_name ( def_id. to_def_id ( ) ) ,
854
+ ) ,
855
+ DefKind :: Trait | DefKind :: TraitAlias => tcx. types . self_param ,
856
+ _ => unreachable ! ( ) ,
857
+ } ;
858
+ assert_only_contains_predicates_from (
859
+ PredicateFilter :: SelfTraitThatDefines ( assoc_name) ,
860
+ bounds,
861
+ self_ty,
862
+ ) ;
863
+
864
+ ty:: EarlyBinder :: bind ( bounds)
848
865
}
849
866
850
867
impl < ' tcx > ItemCtxt < ' tcx > {
0 commit comments