@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, RegionVid};
1010use rustc_mir_dataflow:: points:: { DenseLocationMap , PointIndex } ;
1111use tracing:: debug;
1212
13- use crate :: BorrowIndex ;
1413use crate :: polonius:: LiveLoans ;
14+ use crate :: { BorrowIndex , TyCtxt } ;
1515
1616rustc_index:: newtype_index! {
1717 /// A single integer representing a `ty::Placeholder`.
@@ -22,7 +22,7 @@ rustc_index::newtype_index! {
2222/// An individual element in a region value -- the value of a
2323/// particular region variable consists of a set of these elements.
2424#[ derive( Debug , Clone , PartialEq ) ]
25- pub ( crate ) enum RegionElement {
25+ pub ( crate ) enum RegionElement < ' tcx > {
2626 /// A point in the control-flow graph.
2727 Location ( Location ) ,
2828
@@ -32,7 +32,7 @@ pub(crate) enum RegionElement {
3232
3333 /// A placeholder (e.g., instantiated from a `for<'a> fn(&'a u32)`
3434 /// type).
35- PlaceholderRegion ( ty:: PlaceholderRegion ) ,
35+ PlaceholderRegion ( ty:: PlaceholderRegion < ' tcx > ) ,
3636}
3737
3838/// Records the CFG locations where each region is live. When we initially compute liveness, we use
@@ -196,25 +196,28 @@ impl LivenessValues {
196196/// NLL.
197197#[ derive( Debug , Default ) ]
198198#[ derive( Clone ) ] // FIXME(#146079)
199- pub ( crate ) struct PlaceholderIndices {
200- indices : FxIndexSet < ty:: PlaceholderRegion > ,
199+ pub ( crate ) struct PlaceholderIndices < ' tcx > {
200+ indices : FxIndexSet < ty:: PlaceholderRegion < ' tcx > > ,
201201}
202202
203- impl PlaceholderIndices {
203+ impl < ' tcx > PlaceholderIndices < ' tcx > {
204204 /// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion`
205- pub ( crate ) fn insert ( & mut self , placeholder : ty:: PlaceholderRegion ) -> PlaceholderIndex {
205+ pub ( crate ) fn insert ( & mut self , placeholder : ty:: PlaceholderRegion < ' tcx > ) -> PlaceholderIndex {
206206 let ( index, _) = self . indices . insert_full ( placeholder) ;
207207 index. into ( )
208208 }
209209
210- pub ( crate ) fn lookup_index ( & self , placeholder : ty:: PlaceholderRegion ) -> PlaceholderIndex {
210+ pub ( crate ) fn lookup_index (
211+ & self ,
212+ placeholder : ty:: PlaceholderRegion < ' tcx > ,
213+ ) -> PlaceholderIndex {
211214 self . indices . get_index_of ( & placeholder) . unwrap ( ) . into ( )
212215 }
213216
214217 pub ( crate ) fn lookup_placeholder (
215218 & self ,
216219 placeholder : PlaceholderIndex ,
217- ) -> ty:: PlaceholderRegion {
220+ ) -> ty:: PlaceholderRegion < ' tcx > {
218221 self . indices [ placeholder. index ( ) ]
219222 }
220223
@@ -241,9 +244,9 @@ impl PlaceholderIndices {
241244/// Here, the variable `'0` would contain the free region `'a`,
242245/// because (since it is returned) it must live for at least `'a`. But
243246/// it would also contain various points from within the function.
244- pub ( crate ) struct RegionValues < N : Idx > {
247+ pub ( crate ) struct RegionValues < ' tcx , N : Idx > {
245248 location_map : Rc < DenseLocationMap > ,
246- placeholder_indices : PlaceholderIndices ,
249+ placeholder_indices : PlaceholderIndices < ' tcx > ,
247250 points : SparseIntervalMatrix < N , PointIndex > ,
248251 free_regions : SparseBitMatrix < N , RegionVid > ,
249252
@@ -252,14 +255,14 @@ pub(crate) struct RegionValues<N: Idx> {
252255 placeholders : SparseBitMatrix < N , PlaceholderIndex > ,
253256}
254257
255- impl < N : Idx > RegionValues < N > {
258+ impl < ' tcx , N : Idx > RegionValues < ' tcx , N > {
256259 /// Creates a new set of "region values" that tracks causal information.
257260 /// Each of the regions in num_region_variables will be initialized with an
258261 /// empty set of points and no causal information.
259262 pub ( crate ) fn new (
260263 location_map : Rc < DenseLocationMap > ,
261264 num_universal_regions : usize ,
262- placeholder_indices : PlaceholderIndices ,
265+ placeholder_indices : PlaceholderIndices < ' tcx > ,
263266 ) -> Self {
264267 let num_points = location_map. num_points ( ) ;
265268 let num_placeholders = placeholder_indices. len ( ) ;
@@ -274,7 +277,7 @@ impl<N: Idx> RegionValues<N> {
274277
275278 /// Adds the given element to the value for the given region. Returns whether
276279 /// the element is newly added (i.e., was not already present).
277- pub ( crate ) fn add_element ( & mut self , r : N , elem : impl ToElementIndex ) -> bool {
280+ pub ( crate ) fn add_element ( & mut self , r : N , elem : impl ToElementIndex < ' tcx > ) -> bool {
278281 debug ! ( "add(r={:?}, elem={:?})" , r, elem) ;
279282 elem. add_to_row ( self , r)
280283 }
@@ -293,7 +296,7 @@ impl<N: Idx> RegionValues<N> {
293296 }
294297
295298 /// Returns `true` if the region `r` contains the given element.
296- pub ( crate ) fn contains ( & self , r : N , elem : impl ToElementIndex ) -> bool {
299+ pub ( crate ) fn contains ( & self , r : N , elem : impl ToElementIndex < ' tcx > ) -> bool {
297300 elem. contained_in_row ( self , r)
298301 }
299302
@@ -359,7 +362,7 @@ impl<N: Idx> RegionValues<N> {
359362 pub ( crate ) fn placeholders_contained_in (
360363 & self ,
361364 r : N ,
362- ) -> impl Iterator < Item = ty:: PlaceholderRegion > {
365+ ) -> impl Iterator < Item = ty:: PlaceholderRegion < ' tcx > > {
363366 self . placeholders
364367 . row ( r)
365368 . into_iter ( )
@@ -368,7 +371,7 @@ impl<N: Idx> RegionValues<N> {
368371 }
369372
370373 /// Returns all the elements contained in a given region's value.
371- pub ( crate ) fn elements_contained_in ( & self , r : N ) -> impl Iterator < Item = RegionElement > {
374+ pub ( crate ) fn elements_contained_in ( & self , r : N ) -> impl Iterator < Item = RegionElement < ' tcx > > {
372375 let points_iter = self . locations_outlived_by ( r) . map ( RegionElement :: Location ) ;
373376
374377 let free_regions_iter =
@@ -386,42 +389,50 @@ impl<N: Idx> RegionValues<N> {
386389 }
387390}
388391
389- pub ( crate ) trait ToElementIndex : Debug + Copy {
390- fn add_to_row < N : Idx > ( self , values : & mut RegionValues < N > , row : N ) -> bool ;
392+ pub ( crate ) trait ToElementIndex < ' tcx > : Debug + Copy {
393+ fn add_to_row < N : Idx > ( self , values : & mut RegionValues < ' tcx , N > , row : N ) -> bool ;
391394
392- fn contained_in_row < N : Idx > ( self , values : & RegionValues < N > , row : N ) -> bool ;
395+ fn contained_in_row < N : Idx > ( self , values : & RegionValues < ' tcx , N > , row : N ) -> bool ;
393396}
394397
395- impl ToElementIndex for Location {
396- fn add_to_row < N : Idx > ( self , values : & mut RegionValues < N > , row : N ) -> bool {
398+ impl ToElementIndex < ' _ > for Location {
399+ fn add_to_row < N : Idx > ( self , values : & mut RegionValues < ' _ , N > , row : N ) -> bool {
397400 let index = values. location_map . point_from_location ( self ) ;
398401 values. points . insert ( row, index)
399402 }
400403
401- fn contained_in_row < N : Idx > ( self , values : & RegionValues < N > , row : N ) -> bool {
404+ fn contained_in_row < N : Idx > ( self , values : & RegionValues < ' _ , N > , row : N ) -> bool {
402405 let index = values. location_map . point_from_location ( self ) ;
403406 values. points . contains ( row, index)
404407 }
405408}
406409
407- impl ToElementIndex for RegionVid {
408- fn add_to_row < N : Idx > ( self , values : & mut RegionValues < N > , row : N ) -> bool {
410+ impl ToElementIndex < ' _ > for RegionVid {
411+ fn add_to_row < N : Idx > ( self , values : & mut RegionValues < ' _ , N > , row : N ) -> bool {
409412 values. free_regions . insert ( row, self )
410413 }
411414
412- fn contained_in_row < N : Idx > ( self , values : & RegionValues < N > , row : N ) -> bool {
415+ fn contained_in_row < N : Idx > ( self , values : & RegionValues < ' _ , N > , row : N ) -> bool {
413416 values. free_regions . contains ( row, self )
414417 }
415418}
416419
417- impl ToElementIndex for ty:: PlaceholderRegion {
418- fn add_to_row < N : Idx > ( self , values : & mut RegionValues < N > , row : N ) -> bool {
419- let index = values. placeholder_indices . lookup_index ( self ) ;
420+ impl < ' tcx > ToElementIndex < ' tcx > for ty:: PlaceholderRegion < ' tcx > {
421+ fn add_to_row < N : Idx > ( self , values : & mut RegionValues < ' tcx , N > , row : N ) -> bool
422+ where
423+ Self : Into < ty:: Placeholder < TyCtxt < ' tcx > , ty:: BoundRegion > > ,
424+ {
425+ let placeholder: ty:: Placeholder < TyCtxt < ' tcx > , ty:: BoundRegion > = self . into ( ) ;
426+ let index = values. placeholder_indices . lookup_index ( placeholder) ;
420427 values. placeholders . insert ( row, index)
421428 }
422429
423- fn contained_in_row < N : Idx > ( self , values : & RegionValues < N > , row : N ) -> bool {
424- let index = values. placeholder_indices . lookup_index ( self ) ;
430+ fn contained_in_row < N : Idx > ( self , values : & RegionValues < ' tcx , N > , row : N ) -> bool
431+ where
432+ Self : Into < ty:: Placeholder < TyCtxt < ' tcx > , ty:: BoundRegion > > ,
433+ {
434+ let placeholder: ty:: Placeholder < TyCtxt < ' tcx > , ty:: BoundRegion > = self . into ( ) ;
435+ let index = values. placeholder_indices . lookup_index ( placeholder) ;
425436 values. placeholders . contains ( row, index)
426437 }
427438}
@@ -441,7 +452,9 @@ pub(crate) fn pretty_print_points(
441452}
442453
443454/// For debugging purposes, returns a pretty-printed string of the given region elements.
444- fn pretty_print_region_elements ( elements : impl IntoIterator < Item = RegionElement > ) -> String {
455+ fn pretty_print_region_elements < ' tcx > (
456+ elements : impl IntoIterator < Item = RegionElement < ' tcx > > ,
457+ ) -> String {
445458 let mut result = String :: new ( ) ;
446459 result. push ( '{' ) ;
447460
0 commit comments