@@ -774,32 +774,34 @@ impl<'tcx> ItemCtxt<'tcx> {
774774 only_self_bounds : OnlySelfBounds ,
775775 assoc_name : Option < Ident > ,
776776 ) -> Vec < ( ty:: Predicate < ' tcx > , Span ) > {
777- ast_generics
778- . predicates
779- . iter ( )
780- . filter_map ( |wp| match wp {
781- hir:: WherePredicate :: BoundPredicate ( bp) => Some ( bp) ,
782- _ => None ,
783- } )
784- . flat_map ( |bp| {
785- let bt = if bp. is_param_bound ( param_def_id. to_def_id ( ) ) {
786- Some ( ty)
787- } else if !only_self_bounds. 0 {
788- Some ( self . to_ty ( bp. bounded_ty ) )
789- } else {
790- None
791- } ;
792- let bvars = self . tcx . late_bound_vars ( bp. hir_id ) ;
793-
794- bp. bounds . iter ( ) . filter_map ( move |b| bt. map ( |bt| ( bt, b, bvars) ) ) . filter (
795- |( _, b, _) | match assoc_name {
796- Some ( assoc_name) => self . bound_defines_assoc_item ( b, assoc_name) ,
797- None => true ,
798- } ,
799- )
800- } )
801- . flat_map ( |( bt, b, bvars) | predicates_from_bound ( self , bt, b, bvars) )
802- . collect ( )
777+ let mut bounds = Bounds :: default ( ) ;
778+
779+ for predicate in ast_generics. predicates {
780+ let hir:: WherePredicate :: BoundPredicate ( predicate) = predicate else {
781+ continue ;
782+ } ;
783+
784+ let bound_ty = if predicate. is_param_bound ( param_def_id. to_def_id ( ) ) {
785+ ty
786+ } else if !only_self_bounds. 0 {
787+ self . to_ty ( predicate. bounded_ty )
788+ } else {
789+ continue ;
790+ } ;
791+
792+ let bound_vars = self . tcx . late_bound_vars ( predicate. hir_id ) ;
793+ self . astconv ( ) . add_bounds (
794+ bound_ty,
795+ predicate. bounds . iter ( ) . filter ( |bound| {
796+ assoc_name
797+ . map_or ( true , |assoc_name| self . bound_defines_assoc_item ( bound, assoc_name) )
798+ } ) ,
799+ & mut bounds,
800+ bound_vars,
801+ ) ;
802+ }
803+
804+ bounds. predicates ( ) . collect ( )
803805 }
804806
805807 #[ instrument( level = "trace" , skip( self ) ) ]
@@ -817,19 +819,3 @@ impl<'tcx> ItemCtxt<'tcx> {
817819 }
818820 }
819821}
820-
821- /// Converts a specific `GenericBound` from the AST into a set of
822- /// predicates that apply to the self type. A vector is returned
823- /// because this can be anywhere from zero predicates (`T: ?Sized` adds no
824- /// predicates) to one (`T: Foo`) to many (`T: Bar<X = i32>` adds `T: Bar`
825- /// and `<T as Bar>::X == i32`).
826- fn predicates_from_bound < ' tcx > (
827- astconv : & dyn AstConv < ' tcx > ,
828- param_ty : Ty < ' tcx > ,
829- bound : & ' tcx hir:: GenericBound < ' tcx > ,
830- bound_vars : & ' tcx ty:: List < ty:: BoundVariableKind > ,
831- ) -> Vec < ( ty:: Predicate < ' tcx > , Span ) > {
832- let mut bounds = Bounds :: default ( ) ;
833- astconv. add_bounds ( param_ty, [ bound] . into_iter ( ) , & mut bounds, bound_vars) ;
834- bounds. predicates ( ) . collect ( )
835- }
0 commit comments