1111use super :: universal_regions:: UniversalRegions ;
1212use borrow_check:: nll:: constraints:: graph:: NormalConstraintGraph ;
1313use borrow_check:: nll:: constraints:: { ConstraintSccIndex , ConstraintSet , OutlivesConstraint } ;
14- use borrow_check:: nll:: region_infer:: values:: { RegionElement , ToElementIndex } ;
14+ use borrow_check:: nll:: region_infer:: values:: { PlaceholderIndices , RegionElement , ToElementIndex } ;
1515use borrow_check:: nll:: type_check:: free_region_relations:: UniversalRegionRelations ;
1616use borrow_check:: nll:: type_check:: Locations ;
1717use rustc:: hir:: def_id:: DefId ;
@@ -197,18 +197,21 @@ impl<'tcx> RegionInferenceContext<'tcx> {
197197 . collect ( ) ;
198198
199199 // Compute the max universe used anywhere amongst the regions.
200- let max_universe = definitions
200+ let placeholder_indices : PlaceholderIndices = definitions
201201 . iter ( )
202- . map ( |d| d. universe )
203- . max ( )
204- . unwrap_or ( ty:: UniverseIndex :: ROOT ) ;
202+ . filter_map ( |d| match d. origin {
203+ NLLRegionVariableOrigin :: Placeholder ( placeholder) => Some ( placeholder) ,
204+ _ => None ,
205+ } )
206+ . collect ( ) ;
205207
206208 let constraints = Rc :: new ( outlives_constraints) ; // freeze constraints
207209 let constraint_graph = Rc :: new ( constraints. graph ( definitions. len ( ) ) ) ;
208210 let fr_static = universal_regions. fr_static ;
209211 let constraint_sccs = Rc :: new ( constraints. compute_sccs ( & constraint_graph, fr_static) ) ;
210212
211- let mut scc_values = RegionValues :: new ( elements, universal_regions. len ( ) , max_universe) ;
213+ let mut scc_values =
214+ RegionValues :: new ( elements, universal_regions. len ( ) , placeholder_indices) ;
212215
213216 for region in liveness_constraints. rows ( ) {
214217 let scc = constraint_sccs. scc ( region) ;
@@ -329,17 +332,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
329332 self . scc_values . add_element ( scc, variable) ;
330333 }
331334
332- NLLRegionVariableOrigin :: BoundRegion ( ui) => {
333- // Each placeholder region X outlives its
334- // associated universe but nothing else. Every
335- // placeholder region is always in a universe that
336- // contains `ui` -- but when placeholder regions
337- // are placed into an SCC, that SCC may include
338- // things from other universes that do not include
339- // `ui`.
335+ NLLRegionVariableOrigin :: Placeholder ( placeholder) => {
336+ // Each placeholder region is only visible from
337+ // its universe `ui` and its superuniverses. So we
338+ // can't just add it into `scc` unless the
339+ // universe of the scc can name this region.
340340 let scc_universe = self . scc_universes [ scc] ;
341- if ui . is_subset_of ( scc_universe) {
342- self . scc_values . add_element ( scc, ui ) ;
341+ if placeholder . universe . is_subset_of ( scc_universe) {
342+ self . scc_values . add_element ( scc, placeholder ) ;
343343 } else {
344344 self . add_incompatible_universe ( scc) ;
345345 }
@@ -544,8 +544,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
544544 // B's value, and check whether all of them are nameable
545545 // from universe_a
546546 self . scc_values
547- . subuniverses_contained_in ( scc_b)
548- . all ( |u| u . is_subset_of ( universe_a) )
547+ . placeholders_contained_in ( scc_b)
548+ . all ( |p| p . universe . is_subset_of ( universe_a) )
549549 }
550550
551551 /// Extend `scc` so that it can outlive some placeholder region
@@ -1076,8 +1076,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10761076 ) ;
10771077 }
10781078
1079- NLLRegionVariableOrigin :: BoundRegion ( universe ) => {
1080- self . check_bound_universal_region ( infcx, mir, mir_def_id, fr, universe ) ;
1079+ NLLRegionVariableOrigin :: Placeholder ( placeholder ) => {
1080+ self . check_bound_universal_region ( infcx, mir, mir_def_id, fr, placeholder ) ;
10811081 }
10821082
10831083 NLLRegionVariableOrigin :: Existential => {
@@ -1113,7 +1113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11131113 assert ! ( self . scc_universes[ longer_fr_scc] == ty:: UniverseIndex :: ROOT ) ;
11141114 debug_assert ! (
11151115 self . scc_values
1116- . subuniverses_contained_in ( longer_fr_scc)
1116+ . placeholders_contained_in ( longer_fr_scc)
11171117 . next( )
11181118 . is_none( )
11191119 ) ;
@@ -1181,9 +1181,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11811181 mir : & Mir < ' tcx > ,
11821182 _mir_def_id : DefId ,
11831183 longer_fr : RegionVid ,
1184- universe : ty:: UniverseIndex ,
1184+ placeholder : ty:: Placeholder ,
11851185 ) {
1186- debug ! ( "check_bound_universal_region(fr={:?})" , longer_fr) ;
1186+ debug ! (
1187+ "check_bound_universal_region(fr={:?}, placeholder={:?})" ,
1188+ longer_fr, placeholder,
1189+ ) ;
11871190
11881191 let longer_fr_scc = self . constraint_sccs . scc ( longer_fr) ;
11891192
@@ -1196,7 +1199,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11961199 . find ( |element| match element {
11971200 RegionElement :: Location ( _) => true ,
11981201 RegionElement :: RootUniversalRegion ( _) => true ,
1199- RegionElement :: SubUniversalRegion ( ui ) => * ui != universe ,
1202+ RegionElement :: PlaceholderRegion ( placeholder1 ) => placeholder != * placeholder1 ,
12001203 } )
12011204 } {
12021205 Some ( v) => v,
@@ -1207,10 +1210,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12071210 let error_region = match error_element {
12081211 RegionElement :: Location ( l) => self . find_sub_region_live_at ( longer_fr, l) ,
12091212 RegionElement :: RootUniversalRegion ( r) => r,
1210- RegionElement :: SubUniversalRegion ( error_ui ) => self . definitions
1213+ RegionElement :: PlaceholderRegion ( error_placeholder ) => self . definitions
12111214 . iter_enumerated ( )
12121215 . filter_map ( |( r, definition) | match definition. origin {
1213- NLLRegionVariableOrigin :: BoundRegion ( ui ) if error_ui == ui => Some ( r) ,
1216+ NLLRegionVariableOrigin :: Placeholder ( p ) if p == error_placeholder => Some ( r) ,
12141217 _ => None ,
12151218 } )
12161219 . next ( )
0 commit comments