@@ -123,15 +123,14 @@ pub struct OutlivesConstraint {
123
123
// it is for convenience. Before we dump the constraints in the
124
124
// debugging logs, we sort them, and we'd like the "super region"
125
125
// to be first, etc. (In particular, span should remain last.)
126
-
127
126
/// The region SUP must outlive SUB...
128
- sup : RegionVid ,
127
+ pub sup : RegionVid ,
129
128
130
129
/// Region that must be outlived.
131
- sub : RegionVid ,
130
+ pub sub : RegionVid ,
132
131
133
132
/// At this location.
134
- point : Location ,
133
+ pub point : Location ,
135
134
136
135
/// Later on, we thread the constraints onto a linked list
137
136
/// grouped by their `sub` field. So if you had:
@@ -141,10 +140,10 @@ pub struct OutlivesConstraint {
141
140
/// 0 | `'a: 'b` | Some(2)
142
141
/// 1 | `'b: 'c` | None
143
142
/// 2 | `'c: 'b` | None
144
- next : Option < ConstraintIndex > ,
143
+ pub next : Option < ConstraintIndex > ,
145
144
146
145
/// Where did this constraint arise?
147
- span : Span ,
146
+ pub span : Span ,
148
147
}
149
148
150
149
newtype_index ! ( ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" } ) ;
@@ -240,11 +239,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
240
239
/// `num_region_variables` valid inference variables; the first N
241
240
/// of those will be constant regions representing the free
242
241
/// regions defined in `universal_regions`.
242
+ ///
243
+ /// The `outlives_constraints` and `type_tests` are an initial set
244
+ /// of constraints produced by the MIR type check.
243
245
pub ( crate ) fn new (
244
246
var_infos : VarInfos ,
245
247
universal_regions : UniversalRegions < ' tcx > ,
246
248
mir : & Mir < ' tcx > ,
249
+ outlives_constraints : Vec < OutlivesConstraint > ,
250
+ type_tests : Vec < TypeTest < ' tcx > > ,
247
251
) -> Self {
252
+ // The `next` field should not yet have been initialized:
253
+ debug_assert ! ( outlives_constraints. iter( ) . all( |c| c. next. is_none( ) ) ) ;
254
+
248
255
let num_region_variables = var_infos. len ( ) ;
249
256
let num_universal_regions = universal_regions. len ( ) ;
250
257
@@ -262,8 +269,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
262
269
liveness_constraints : RegionValues :: new ( elements, num_region_variables) ,
263
270
inferred_values : None ,
264
271
dependency_map : None ,
265
- constraints : IndexVec :: new ( ) ,
266
- type_tests : Vec :: new ( ) ,
272
+ constraints : IndexVec :: from_raw ( outlives_constraints ) ,
273
+ type_tests,
267
274
universal_regions,
268
275
} ;
269
276
@@ -346,15 +353,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
346
353
where
347
354
R : ToRegionVid ,
348
355
{
349
- let inferred_values = self . inferred_values
356
+ let inferred_values = self
357
+ . inferred_values
350
358
. as_ref ( )
351
359
. expect ( "region values not yet inferred" ) ;
352
360
inferred_values. contains ( r. to_region_vid ( ) , p)
353
361
}
354
362
355
363
/// Returns access to the value of `r` for debugging purposes.
356
364
crate fn region_value_str ( & self , r : RegionVid ) -> String {
357
- let inferred_values = self . inferred_values
365
+ let inferred_values = self
366
+ . inferred_values
358
367
. as_ref ( )
359
368
. expect ( "region values not yet inferred" ) ;
360
369
@@ -397,11 +406,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
397
406
} ) ;
398
407
}
399
408
400
- /// Add a "type test" that must be satisfied.
401
- pub ( super ) fn add_type_test ( & mut self , type_test : TypeTest < ' tcx > ) {
402
- self . type_tests . push ( type_test) ;
403
- }
404
-
405
409
/// Perform region inference and report errors if we see any
406
410
/// unsatisfiable constraints. If this is a closure, returns the
407
411
/// region requirements to propagate to our creator, if any.
@@ -596,7 +600,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
596
600
if self . universal_regions . is_universal_region ( r) {
597
601
return self . definitions [ r] . external_name ;
598
602
} else {
599
- let inferred_values = self . inferred_values
603
+ let inferred_values = self
604
+ . inferred_values
600
605
. as_ref ( )
601
606
. expect ( "region values not yet inferred" ) ;
602
607
let upper_bound = self . universal_upper_bound ( r) ;
@@ -635,8 +640,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
635
640
// region, which ensures it can be encoded in a `ClosureOutlivesRequirement`.
636
641
let lower_bound_plus = self . non_local_universal_upper_bound ( * lower_bound) ;
637
642
assert ! ( self . universal_regions. is_universal_region( lower_bound_plus) ) ;
638
- assert ! ( !self . universal_regions
639
- . is_local_free_region( lower_bound_plus) ) ;
643
+ assert ! (
644
+ !self
645
+ . universal_regions
646
+ . is_local_free_region( lower_bound_plus)
647
+ ) ;
640
648
641
649
propagated_outlives_requirements. push ( ClosureOutlivesRequirement {
642
650
subject,
@@ -664,7 +672,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
664
672
) -> Option < ClosureOutlivesSubject < ' gcx > > {
665
673
let tcx = infcx. tcx ;
666
674
let gcx = tcx. global_tcx ( ) ;
667
- let inferred_values = self . inferred_values
675
+ let inferred_values = self
676
+ . inferred_values
668
677
. as_ref ( )
669
678
. expect ( "region values not yet inferred" ) ;
670
679
@@ -845,7 +854,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
845
854
sup_region, sub_region, point
846
855
) ;
847
856
848
- let inferred_values = self . inferred_values
857
+ let inferred_values = self
858
+ . inferred_values
849
859
. as_ref ( )
850
860
. expect ( "values for regions not yet inferred" ) ;
851
861
@@ -912,7 +922,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
912
922
) {
913
923
// The universal regions are always found in a prefix of the
914
924
// full list.
915
- let universal_definitions = self . definitions
925
+ let universal_definitions = self
926
+ . definitions
916
927
. iter_enumerated ( )
917
928
. take_while ( |( _, fr_definition) | fr_definition. is_universal ) ;
918
929
0 commit comments