@@ -557,7 +557,11 @@ pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
557557    tcx :  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>(
586590    let  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 ( _) ) ; 
590594        return  tcx. explicit_super_predicates_of ( trait_def_id) ; 
591595    } ; 
592596
@@ -606,12 +610,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
606610    let  mut  bounds = Bounds :: default ( ) ; 
607611    icx. lowerer ( ) . lower_bounds ( self_param_ty,  superbounds,  & mut  bounds,  ty:: List :: empty ( ) ,  filter) ; 
608612
609-     let  where_bounds_that_match = icx. probe_ty_param_bounds_in_generics ( 
610-         generics, 
611-         item. owner_id . def_id , 
612-         self_param_ty, 
613-         filter, 
614-     ) ; 
613+     let  where_bounds_that_match =
614+         icx. probe_ty_param_bounds_in_generics ( generics,  item. owner_id . def_id ,  filter) ; 
615615
616616    // Combine the two lists to form the complete set of superbounds: 
617617    let  implied_bounds =
@@ -652,7 +652,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
652652} 
653653
654654// 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. 
656656// This is very important since downstream code relies on this being correct. 
657657pub ( super )  fn  assert_only_contains_predicates_from < ' tcx > ( 
658658    filter :  PredicateFilter , 
@@ -664,7 +664,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
664664    } 
665665
666666    match  filter { 
667-         PredicateFilter :: SelfOnly  |  PredicateFilter :: SelfThatDefines ( _ )   => { 
667+         PredicateFilter :: SelfOnly  => { 
668668            for  ( clause,  _)  in  bounds { 
669669                match  clause. kind ( ) . skip_binder ( )  { 
670670                    ty:: ClauseKind :: Trait ( trait_predicate)  => { 
@@ -704,6 +704,33 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
704704                } 
705705            } 
706706        } 
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+         } 
707734        PredicateFilter :: ConstIfConst  => { 
708735            for  ( clause,  _)  in  bounds { 
709736                match  clause. kind ( ) . skip_binder ( )  { 
@@ -767,21 +794,16 @@ pub(super) fn type_param_predicates<'tcx>(
767794        None  => { } 
768795    } 
769796
770-     use  rustc_hir:: * ; 
771-     use  rustc_middle:: ty:: Ty ; 
772- 
773797    // In the HIR, bounds can derive from two places. Either 
774798    // written inline like `<T: Foo>` or in a where-clause like 
775799    // `where T: Foo`. 
776800
777801    let  param_id = tcx. local_def_id_to_hir_id ( def_id) ; 
778802    let  param_owner = tcx. hir ( ) . ty_param_owner ( def_id) ; 
779-     let  generics = tcx. generics_of ( param_owner) ; 
780-     let  index = generics. param_def_id_to_index [ & def_id. to_def_id ( ) ] ; 
781-     let  ty = Ty :: new_param ( tcx,  index,  tcx. hir ( ) . ty_param_name ( def_id) ) ; 
782803
783804    // Don't look for bounds where the type parameter isn't in scope. 
784805    let  parent = if  item_def_id == param_owner { 
806+         // FIXME: Shouldn't this be unreachable? 
785807        None 
786808    }  else  { 
787809        tcx. generics_of ( item_def_id) . parent . map ( |def_id| def_id. expect_local ( ) ) 
@@ -801,8 +823,9 @@ pub(super) fn type_param_predicates<'tcx>(
801823    let  Some ( hir_generics)  = hir_node. generics ( )  else  { 
802824        return  result; 
803825    } ; 
826+ 
804827    if  let  Node :: Item ( item)  = hir_node
805-         && let  ItemKind :: Trait ( ..)  = item. kind 
828+         && let  hir :: ItemKind :: Trait ( ..)  = item. kind 
806829        // Implied `Self: Trait` and supertrait bounds. 
807830        && param_id == item_hir_id
808831    { 
@@ -811,23 +834,34 @@ pub(super) fn type_param_predicates<'tcx>(
811834    } 
812835
813836    let  icx = ItemCtxt :: new ( tcx,  item_def_id) ; 
814-     let  extra_predicates = extend. into_iter ( ) . chain ( 
815-         icx. probe_ty_param_bounds_in_generics ( 
816-             hir_generics, 
817-             def_id, 
818-             ty, 
819-             PredicateFilter :: SelfThatDefines ( assoc_name) , 
820-         ) 
821-         . into_iter ( ) 
822-         . filter ( |( predicate,  _) | match  predicate. kind ( ) . skip_binder ( )  { 
823-             ty:: ClauseKind :: Trait ( data)  => data. self_ty ( ) . is_param ( index) , 
824-             _ => false , 
825-         } ) , 
837+     let  extra_predicates = extend. into_iter ( ) . chain ( icx. probe_ty_param_bounds_in_generics ( 
838+         hir_generics, 
839+         def_id, 
840+         PredicateFilter :: SelfTraitThatDefines ( assoc_name) , 
841+     ) ) ; 
842+ 
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, 
826862    ) ; 
827863
828-     ty:: EarlyBinder :: bind ( 
829-         tcx. arena . alloc_from_iter ( result. skip_binder ( ) . iter ( ) . copied ( ) . chain ( extra_predicates) ) , 
830-     ) 
864+     ty:: EarlyBinder :: bind ( bounds) 
831865} 
832866
833867impl < ' tcx >  ItemCtxt < ' tcx >  { 
@@ -841,7 +875,6 @@ impl<'tcx> ItemCtxt<'tcx> {
841875        & self , 
842876        hir_generics :  & ' tcx  hir:: Generics < ' tcx > , 
843877        param_def_id :  LocalDefId , 
844-         ty :  Ty < ' tcx > , 
845878        filter :  PredicateFilter , 
846879    )  -> Vec < ( ty:: Clause < ' tcx > ,  Span ) >  { 
847880        let  mut  bounds = Bounds :: default ( ) ; 
@@ -851,13 +884,21 @@ impl<'tcx> ItemCtxt<'tcx> {
851884                continue ; 
852885            } ; 
853886
854-             let  bound_ty = if  predicate. is_param_bound ( param_def_id. to_def_id ( ) )  { 
855-                 ty
856-             }  else  if  matches ! ( filter,  PredicateFilter :: All )  { 
857-                 self . lowerer ( ) . lower_ty_maybe_return_type_notation ( predicate. bounded_ty ) 
858-             }  else  { 
859-                 continue ; 
860-             } ; 
887+             match  filter { 
888+                 _ if  predicate. is_param_bound ( param_def_id. to_def_id ( ) )  => { 
889+                     // Ok 
890+                 } 
891+                 PredicateFilter :: All  => { 
892+                     // Ok 
893+                 } 
894+                 PredicateFilter :: SelfOnly 
895+                 | PredicateFilter :: SelfTraitThatDefines ( _) 
896+                 | PredicateFilter :: SelfConstIfConst 
897+                 | PredicateFilter :: SelfAndAssociatedTypeBounds  => continue , 
898+                 PredicateFilter :: ConstIfConst  => unreachable ! ( ) , 
899+             } 
900+ 
901+             let  bound_ty = self . lowerer ( ) . lower_ty_maybe_return_type_notation ( predicate. bounded_ty ) ; 
861902
862903            let  bound_vars = self . tcx . late_bound_vars ( predicate. hir_id ) ; 
863904            self . lowerer ( ) . lower_bounds ( 
0 commit comments