@@ -51,10 +51,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
5151
5252 // Start with anything like `T: 'a` we can scrape from the
5353 // environment
54- let param_bounds = self
55- . declared_generic_bounds_from_env ( GenericKind :: Param ( param_ty) )
56- . into_iter ( )
57- . map ( |outlives| outlives. 1 ) ;
54+ let param_bounds =
55+ self . declared_generic_bounds_from_env ( param_ty) . map ( |outlives| outlives. 1 ) ;
5856
5957 // Add in the default bound of fn body that applies to all in
6058 // scope type parameters:
@@ -79,12 +77,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
7977 pub fn projection_approx_declared_bounds_from_env (
8078 & self ,
8179 projection_ty : ty:: ProjectionTy < ' tcx > ,
82- ) -> Vec < ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > {
83- let projection_ty = GenericKind :: Projection ( projection_ty) . to_ty ( self . tcx ) ;
84- let erased_projection_ty = self . tcx . erase_regions ( & projection_ty) ;
85- self . declared_generic_bounds_from_env_with_compare_fn ( |ty| {
80+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
81+ {
82+ let tcx = self . tcx ;
83+
84+ let projection_ty = GenericKind :: Projection ( projection_ty) . to_ty ( tcx) ;
85+ let erased_projection_ty = tcx. erase_regions ( & projection_ty) ;
86+ self . declared_generic_bounds_from_env_with_compare_fn ( move |ty| {
8687 if let ty:: Projection ( ..) = ty. kind {
87- let erased_ty = self . tcx . erase_regions ( & ty) ;
88+ let erased_ty = tcx. erase_regions ( & ty) ;
8889 erased_ty == erased_projection_ty
8990 } else {
9091 false
@@ -95,10 +96,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9596 /// Searches the where-clauses in scope for regions that
9697 /// `projection_ty` is known to outlive. Currently requires an
9798 /// exact match.
98- pub fn projection_declared_bounds_from_trait (
99- & self ,
99+ pub fn projection_declared_bounds_from_trait < ' a > (
100+ & ' a self ,
100101 projection_ty : ty:: ProjectionTy < ' tcx > ,
101- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > {
102+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
103+ where
104+ ' a : ' cx ,
105+ {
102106 self . declared_projection_bounds_from_trait ( projection_ty)
103107 }
104108
@@ -127,7 +131,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
127131 // Extend with bounds that we can find from the trait.
128132 let trait_bounds = self
129133 . projection_declared_bounds_from_trait ( projection_ty)
130- . into_iter ( )
131134 . map ( |r| VerifyBound :: OutlivedBy ( r) ) ;
132135
133136 // see the extensive comment in projection_must_outlive
@@ -138,17 +141,18 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
138141 }
139142
140143 fn recursive_type_bound ( & self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
141- let mut bounds = ty. walk_shallow ( ) . map ( |subty| self . type_bound ( subty) ) . collect :: < Vec < _ > > ( ) ;
142-
143- let mut regions = smallvec ! [ ] ;
144- ty. push_regions ( & mut regions) ;
145- regions. retain ( |r| !r. is_late_bound ( ) ) ; // ignore late-bound regions
146- bounds. push ( VerifyBound :: AllBounds (
147- regions. into_iter ( ) . map ( |r| VerifyBound :: OutlivedBy ( r) ) . collect ( ) ,
148- ) ) ;
149-
150- // remove bounds that must hold, since they are not interesting
151- bounds. retain ( |b| !b. must_hold ( ) ) ;
144+ let mut bounds = ty
145+ . walk_shallow ( )
146+ . map ( |subty| self . type_bound ( subty) )
147+ . chain ( Some ( VerifyBound :: AllBounds (
148+ // ignore late-bound regions
149+ ty. regions ( )
150+ . filter ( |r| !r. is_late_bound ( ) )
151+ . map ( |r| VerifyBound :: OutlivedBy ( r) )
152+ . collect ( ) ,
153+ ) ) )
154+ . filter ( |b| !b. must_hold ( ) )
155+ . collect :: < Vec < _ > > ( ) ;
152156
153157 if bounds. len ( ) == 1 { bounds. pop ( ) . unwrap ( ) } else { VerifyBound :: AllBounds ( bounds) }
154158 }
@@ -161,16 +165,18 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
161165 /// bounds, but all the bounds it returns can be relied upon.
162166 fn declared_generic_bounds_from_env (
163167 & self ,
164- generic : GenericKind < ' tcx > ,
165- ) -> Vec < ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > {
168+ generic : ty:: ParamTy ,
169+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
170+ {
166171 let generic_ty = generic. to_ty ( self . tcx ) ;
167- self . declared_generic_bounds_from_env_with_compare_fn ( |ty| ty == generic_ty)
172+ self . declared_generic_bounds_from_env_with_compare_fn ( move |ty| ty == generic_ty)
168173 }
169174
170175 fn declared_generic_bounds_from_env_with_compare_fn (
171176 & self ,
172- compare_ty : impl Fn ( Ty < ' tcx > ) -> bool ,
173- ) -> Vec < ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > {
177+ compare_ty : impl Fn ( Ty < ' tcx > ) -> bool + Clone + ' tcx + ' cx ,
178+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
179+ {
174180 let tcx = self . tcx ;
175181
176182 // To start, collect bounds from user environment. Note that
@@ -180,7 +186,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
180186 // like `T` and `T::Item`. It may not work as well for things
181187 // like `<T as Foo<'a>>::Item`.
182188 let c_b = self . param_env . caller_bounds ;
183- let param_bounds = self . collect_outlives_from_predicate_list ( & compare_ty, c_b) ;
189+ let param_bounds = self . collect_outlives_from_predicate_list ( compare_ty. clone ( ) , c_b) ;
184190
185191 // Next, collect regions we scraped from the well-formedness
186192 // constraints in the fn signature. To do that, we walk the list
@@ -193,7 +199,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
193199 // The problem is that the type of `x` is `&'a A`. To be
194200 // well-formed, then, A must be lower-generic by `'a`, but we
195201 // don't know that this holds from first principles.
196- let from_region_bound_pairs = self . region_bound_pairs . iter ( ) . filter_map ( |& ( r, p) | {
202+ let from_region_bound_pairs = self . region_bound_pairs . iter ( ) . filter_map ( move |& ( r, p) | {
197203 debug ! (
198204 "declared_generic_bounds_from_env_with_compare_fn: region_bound_pair = {:?}" ,
199205 ( r, p)
@@ -202,15 +208,12 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
202208 compare_ty ( p_ty) . then_some ( ty:: OutlivesPredicate ( p_ty, r) )
203209 } ) ;
204210
205- param_bounds
206- . chain ( from_region_bound_pairs)
207- . inspect ( |bound| {
208- debug ! (
209- "declared_generic_bounds_from_env_with_compare_fn: result predicate = {:?}" ,
210- bound
211- )
212- } )
213- . collect ( )
211+ param_bounds. chain ( from_region_bound_pairs) . inspect ( |bound| {
212+ debug ! (
213+ "declared_generic_bounds_from_env_with_compare_fn: result predicate = {:?}" ,
214+ bound
215+ )
216+ } )
214217 }
215218
216219 /// Given a projection like `<T as Foo<'x>>::Bar`, returns any bounds
@@ -225,10 +228,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
225228 /// then this function would return `'x`. This is subject to the
226229 /// limitations around higher-ranked bounds described in
227230 /// `region_bounds_declared_on_associated_item`.
228- fn declared_projection_bounds_from_trait (
229- & self ,
231+ fn declared_projection_bounds_from_trait < ' a > (
232+ & ' a self ,
230233 projection_ty : ty:: ProjectionTy < ' tcx > ,
231- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > {
234+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
235+ where
236+ ' a : ' cx ,
237+ {
232238 debug ! ( "projection_bounds(projection_ty={:?})" , projection_ty) ;
233239 let tcx = self . tcx ;
234240 self . region_bounds_declared_on_associated_item ( projection_ty. item_def_id )
@@ -265,10 +271,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
265271 ///
266272 /// This is for simplicity, and because we are not really smart
267273 /// enough to cope with such bounds anywhere.
268- fn region_bounds_declared_on_associated_item (
269- & self ,
274+ fn region_bounds_declared_on_associated_item < ' a > (
275+ & ' a self ,
270276 assoc_item_def_id : DefId ,
271- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > {
277+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
278+ where
279+ ' a : ' cx ,
280+ {
272281 let tcx = self . tcx ;
273282 let assoc_item = tcx. associated_item ( assoc_item_def_id) ;
274283 let trait_def_id = assoc_item. container . assert_trait ( ) ;
@@ -291,7 +300,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
291300 /// otherwise want a precise match.
292301 fn collect_outlives_from_predicate_list (
293302 & self ,
294- compare_ty : impl Fn ( Ty < ' tcx > ) -> bool ,
303+ compare_ty : impl Fn ( Ty < ' tcx > ) -> bool + ' tcx ,
295304 predicates : impl IntoIterator < Item = impl AsRef < ty:: Predicate < ' tcx > > > ,
296305 ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > {
297306 predicates
0 commit comments