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