@@ -70,48 +70,61 @@ fn compute_implied_outlives_bounds<'tcx>(
7070 let obligations = wf:: obligations ( ocx. infcx , param_env, CRATE_DEF_ID , 0 , arg, DUMMY_SP )
7171 . unwrap_or_default ( ) ;
7272
73- // While these predicates should all be implied by other parts of
74- // the program, they are still relevant as they may constrain
75- // inference variables, which is necessary to add the correct
76- // implied bounds in some cases, mostly when dealing with projections.
77- ocx. register_obligations (
78- obligations. iter ( ) . filter ( |o| o. predicate . has_non_region_infer ( ) ) . cloned ( ) ,
79- ) ;
80-
81- // From the full set of obligations, just filter down to the
82- // region relationships.
83- outlives_bounds. extend ( obligations. into_iter ( ) . filter_map ( |obligation| {
73+ for obligation in obligations {
8474 debug ! ( ?obligation) ;
8575 assert ! ( !obligation. has_escaping_bound_vars( ) ) ;
86- match obligation. predicate . kind ( ) . no_bound_vars ( ) {
87- None => None ,
88- Some ( pred) => match pred {
89- ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( ..) )
90- | ty:: PredicateKind :: Subtype ( ..)
91- | ty:: PredicateKind :: Coerce ( ..)
92- | ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( ..) )
93- | ty:: PredicateKind :: ClosureKind ( ..)
94- | ty:: PredicateKind :: ObjectSafe ( ..)
95- | ty:: PredicateKind :: ConstEvaluatable ( ..)
96- | ty:: PredicateKind :: ConstEquate ( ..)
97- | ty:: PredicateKind :: Ambiguous
98- | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => None ,
99- ty:: PredicateKind :: WellFormed ( arg) => {
100- wf_args. push ( arg) ;
101- None
76+
77+ // While these predicates should all be implied by other parts of
78+ // the program, they are still relevant as they may constrain
79+ // inference variables, which is necessary to add the correct
80+ // implied bounds in some cases, mostly when dealing with projections.
81+ //
82+ // Another important point here: we only register `Projection`
83+ // predicates, since otherwise we might register outlives
84+ // predicates containing inference variables, and we don't
85+ // learn anything new from those.
86+ if obligation. predicate . has_non_region_infer ( ) {
87+ match obligation. predicate . kind ( ) . skip_binder ( ) {
88+ ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( ..) ) => {
89+ ocx. register_obligation ( obligation. clone ( ) ) ;
10290 }
91+ _ => { }
92+ }
93+ }
10394
104- ty:: PredicateKind :: Clause ( ty:: Clause :: RegionOutlives (
105- ty:: OutlivesPredicate ( r_a, r_b) ,
106- ) ) => Some ( ty:: OutlivesPredicate ( r_a. into ( ) , r_b) ) ,
95+ let pred = match obligation. predicate . kind ( ) . no_bound_vars ( ) {
96+ None => continue ,
97+ Some ( pred) => pred,
98+ } ;
99+ match pred {
100+ ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( ..) )
101+ | ty:: PredicateKind :: Subtype ( ..)
102+ | ty:: PredicateKind :: Coerce ( ..)
103+ | ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( ..) )
104+ | ty:: PredicateKind :: ClosureKind ( ..)
105+ | ty:: PredicateKind :: ObjectSafe ( ..)
106+ | ty:: PredicateKind :: ConstEvaluatable ( ..)
107+ | ty:: PredicateKind :: ConstEquate ( ..)
108+ | ty:: PredicateKind :: Ambiguous
109+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => { }
110+
111+ // We need to search through *all* WellFormed predicates
112+ ty:: PredicateKind :: WellFormed ( arg) => {
113+ wf_args. push ( arg) ;
114+ }
115+
116+ // We need to register region relationships
117+ ty:: PredicateKind :: Clause ( ty:: Clause :: RegionOutlives ( ty:: OutlivesPredicate (
118+ r_a,
119+ r_b,
120+ ) ) ) => outlives_bounds. push ( ty:: OutlivesPredicate ( r_a. into ( ) , r_b) ) ,
107121
108- ty:: PredicateKind :: Clause ( ty:: Clause :: TypeOutlives ( ty:: OutlivesPredicate (
109- ty_a,
110- r_b,
111- ) ) ) => Some ( ty:: OutlivesPredicate ( ty_a. into ( ) , r_b) ) ,
112- } ,
122+ ty:: PredicateKind :: Clause ( ty:: Clause :: TypeOutlives ( ty:: OutlivesPredicate (
123+ ty_a,
124+ r_b,
125+ ) ) ) => outlives_bounds. push ( ty:: OutlivesPredicate ( ty_a. into ( ) , r_b) ) ,
113126 }
114- } ) ) ;
127+ }
115128 }
116129
117130 // This call to `select_all_or_error` is necessary to constrain inference variables, which we
0 commit comments