@@ -17,6 +17,7 @@ use infer::region_constraints::GenericKind;
17
17
use infer:: region_constraints:: RegionConstraintData ;
18
18
use infer:: region_constraints:: VerifyBound ;
19
19
use middle:: free_region:: RegionRelations ;
20
+ use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
20
21
use rustc_data_structures:: fx:: FxHashSet ;
21
22
use rustc_data_structures:: graph:: { self , Direction , NodeIndex , OUTGOING } ;
22
23
use std:: fmt;
@@ -29,7 +30,7 @@ use ty::{ReLateBound, ReScope, ReSkolemized, ReVar};
29
30
mod graphviz;
30
31
31
32
pub struct LexicalRegionResolutions < ' tcx > {
32
- values : Vec < VarValue < ' tcx > > ,
33
+ values : IndexVec < RegionVid , VarValue < ' tcx > > ,
33
34
error_region : ty:: Region < ' tcx > ,
34
35
}
35
36
@@ -114,7 +115,7 @@ impl<'tcx> RegionConstraintData<'tcx> {
114
115
115
116
( & ReVar ( v_id) , _) | ( _, & ReVar ( v_id) ) => {
116
117
span_bug ! (
117
- self . var_origins[ v_id. index as usize ] . span( ) ,
118
+ self . var_origins[ v_id] . span( ) ,
118
119
"lub_concrete_regions invoked with non-concrete \
119
120
regions: {:?}, {:?}",
120
121
a,
@@ -211,7 +212,7 @@ impl<'tcx> RegionConstraintData<'tcx> {
211
212
fn construct_var_data ( & self , tcx : TyCtxt < ' _ , ' _ , ' tcx > ) -> LexicalRegionResolutions < ' tcx > {
212
213
LexicalRegionResolutions {
213
214
error_region : tcx. types . re_static ,
214
- values : ( 0 ..self . num_vars ( ) as usize )
215
+ values : ( 0 ..self . num_vars ( ) )
215
216
. map ( |_| VarValue :: Value ( tcx. types . re_empty ) )
216
217
. collect ( ) ,
217
218
}
@@ -240,11 +241,20 @@ impl<'tcx> RegionConstraintData<'tcx> {
240
241
241
242
let seeds: Vec < _ > = self . givens . iter ( ) . cloned ( ) . collect ( ) ;
242
243
for ( r, vid) in seeds {
244
+
245
+ // While all things transitively reachable in the graph
246
+ // from the variable (`'0` in the example above).
243
247
let seed_index = NodeIndex ( vid. index as usize ) ;
244
248
for succ_index in graph. depth_traverse ( seed_index, OUTGOING ) {
245
- let succ_index = succ_index. 0 as u32 ;
249
+ let succ_index = succ_index. 0 ;
250
+
251
+ // The first N nodes correspond to the region
252
+ // variables. Other nodes correspond to constant
253
+ // regions.
246
254
if succ_index < self . num_vars ( ) {
247
- let succ_vid = RegionVid { index : succ_index } ;
255
+ let succ_vid = RegionVid :: new ( succ_index) ;
256
+
257
+ // Add `'c <= '1`.
248
258
self . givens . insert ( ( r, succ_vid) ) ;
249
259
}
250
260
}
@@ -442,11 +452,10 @@ impl<'tcx> RegionConstraintData<'tcx> {
442
452
// idea is to report errors that derive from independent
443
453
// regions of the graph, but not those that derive from
444
454
// overlapping locations.
445
- let mut dup_vec = vec ! [ u32 :: MAX ; self . num_vars( ) as usize ] ;
455
+ let mut dup_vec = vec ! [ u32 :: MAX ; self . num_vars( ) ] ;
446
456
447
- for index in 0 ..self . num_vars ( ) {
448
- let node_vid = RegionVid { index } ;
449
- match var_data. value ( node_vid) {
457
+ for ( node_vid, value) in var_data. values . iter_enumerated ( ) {
458
+ match * value {
450
459
VarValue :: Value ( _) => { /* Inference successful */ }
451
460
VarValue :: ErrorValue => {
452
461
/* Inference impossible, this value contains
@@ -560,7 +569,7 @@ impl<'tcx> RegionConstraintData<'tcx> {
560
569
for lower_bound in & lower_bounds {
561
570
for upper_bound in & upper_bounds {
562
571
if !region_rels. is_subregion_of ( lower_bound. region , upper_bound. region ) {
563
- let origin = self . var_origins [ node_idx. index as usize ] . clone ( ) ;
572
+ let origin = self . var_origins [ node_idx] . clone ( ) ;
564
573
debug ! (
565
574
"region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
566
575
sup: {:?}",
@@ -582,7 +591,7 @@ impl<'tcx> RegionConstraintData<'tcx> {
582
591
}
583
592
584
593
span_bug ! (
585
- self . var_origins[ node_idx. index as usize ] . span( ) ,
594
+ self . var_origins[ node_idx] . span( ) ,
586
595
"collect_error_for_expanding_node() could not find \
587
596
error for var {:?}, lower_bounds={:?}, \
588
597
upper_bounds={:?}",
@@ -741,15 +750,15 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
741
750
}
742
751
743
752
fn value ( & self , rid : RegionVid ) -> & VarValue < ' tcx > {
744
- & self . values [ rid. index as usize ]
753
+ & self . values [ rid]
745
754
}
746
755
747
756
fn value_mut ( & mut self , rid : RegionVid ) -> & mut VarValue < ' tcx > {
748
- & mut self . values [ rid. index as usize ]
757
+ & mut self . values [ rid]
749
758
}
750
759
751
760
pub fn resolve_var ( & self , rid : RegionVid ) -> ty:: Region < ' tcx > {
752
- let result = match self . values [ rid. index as usize ] {
761
+ let result = match self . values [ rid] {
753
762
VarValue :: Value ( r) => r,
754
763
VarValue :: ErrorValue => self . error_region ,
755
764
} ;
0 commit comments