@@ -14,6 +14,7 @@ use borrow_check::nll::constraints::{
14
14
ConstraintIndex , ConstraintSccIndex , ConstraintSet , OutlivesConstraint ,
15
15
} ;
16
16
use borrow_check:: nll:: region_infer:: values:: { RegionElement , ToElementIndex } ;
17
+ use borrow_check:: nll:: type_check:: free_region_relations:: UniversalRegionRelations ;
17
18
use borrow_check:: nll:: type_check:: Locations ;
18
19
use rustc:: hir:: def_id:: DefId ;
19
20
use rustc:: infer:: canonical:: QueryRegionConstraint ;
@@ -80,8 +81,12 @@ pub struct RegionInferenceContext<'tcx> {
80
81
type_tests : Vec < TypeTest < ' tcx > > ,
81
82
82
83
/// Information about the universally quantified regions in scope
83
- /// on this function and their (known) relations to one another .
84
+ /// on this function.
84
85
universal_regions : Rc < UniversalRegions < ' tcx > > ,
86
+
87
+ /// Information about how the universally quantified regions in
88
+ /// scope on this function relate to one another.
89
+ universal_region_relations : Rc < UniversalRegionRelations < ' tcx > > ,
85
90
}
86
91
87
92
struct RegionDefinition < ' tcx > {
@@ -206,15 +211,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
206
211
/// of constraints produced by the MIR type check.
207
212
pub ( crate ) fn new (
208
213
var_infos : VarInfos ,
209
- universal_regions : UniversalRegions < ' tcx > ,
214
+ universal_regions : Rc < UniversalRegions < ' tcx > > ,
215
+ universal_region_relations : Rc < UniversalRegionRelations < ' tcx > > ,
210
216
_mir : & Mir < ' tcx > ,
211
217
outlives_constraints : ConstraintSet ,
212
218
type_tests : Vec < TypeTest < ' tcx > > ,
213
219
liveness_constraints : LivenessValues < RegionVid > ,
214
220
elements : & Rc < RegionValueElements > ,
215
221
) -> Self {
216
- let universal_regions = Rc :: new ( universal_regions) ;
217
-
218
222
// Create a RegionDefinition for each inference variable.
219
223
let definitions: IndexVec < _ , _ > = var_infos
220
224
. into_iter ( )
@@ -251,6 +255,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
251
255
scc_values,
252
256
type_tests,
253
257
universal_regions,
258
+ universal_region_relations,
254
259
} ;
255
260
256
261
result. init_free_and_bound_regions ( ) ;
@@ -308,8 +313,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
308
313
for ( external_name, variable) in self . universal_regions . named_universal_regions ( ) {
309
314
debug ! (
310
315
"init_universal_regions: region {:?} has external name {:?}" ,
311
- variable,
312
- external_name
316
+ variable, external_name
313
317
) ;
314
318
self . definitions [ variable] . external_name = Some ( external_name) ;
315
319
}
@@ -419,10 +423,20 @@ impl<'tcx> RegionInferenceContext<'tcx> {
419
423
} ;
420
424
421
425
self . check_type_tests (
422
- infcx, mir, mir_def_id, outlives_requirements. as_mut ( ) , errors_buffer) ;
426
+ infcx,
427
+ mir,
428
+ mir_def_id,
429
+ outlives_requirements. as_mut ( ) ,
430
+ errors_buffer,
431
+ ) ;
423
432
424
433
self . check_universal_regions (
425
- infcx, mir, mir_def_id, outlives_requirements. as_mut ( ) , errors_buffer) ;
434
+ infcx,
435
+ mir,
436
+ mir_def_id,
437
+ outlives_requirements. as_mut ( ) ,
438
+ errors_buffer,
439
+ ) ;
426
440
427
441
let outlives_requirements = outlives_requirements. unwrap_or ( vec ! [ ] ) ;
428
442
@@ -581,13 +595,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
581
595
if let Some ( lower_bound_region) = lower_bound_region {
582
596
let region_scope_tree = & tcx. region_scope_tree ( mir_def_id) ;
583
597
let type_test_span = type_test. locations . span ( mir) ;
584
- infcx. construct_generic_bound_failure (
585
- region_scope_tree,
586
- type_test_span,
587
- None ,
588
- type_test. generic_kind ,
589
- lower_bound_region,
590
- ) . buffer ( errors_buffer) ;
598
+ infcx
599
+ . construct_generic_bound_failure (
600
+ region_scope_tree,
601
+ type_test_span,
602
+ None ,
603
+ type_test. generic_kind ,
604
+ lower_bound_region,
605
+ )
606
+ . buffer ( errors_buffer) ;
591
607
} else {
592
608
// FIXME. We should handle this case better. It
593
609
// indicates that we have e.g. some region variable
@@ -599,10 +615,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
599
615
// iterating over the universal regions and reporting
600
616
// an error that multiple bounds are required.
601
617
let type_test_span = type_test. locations . span ( mir) ;
602
- tcx. sess . struct_span_err (
603
- type_test_span,
604
- & format ! ( "`{}` does not live long enough" , type_test. generic_kind, ) ,
605
- ) . buffer ( errors_buffer) ;
618
+ tcx. sess
619
+ . struct_span_err (
620
+ type_test_span,
621
+ & format ! ( "`{}` does not live long enough" , type_test. generic_kind, ) ,
622
+ )
623
+ . buffer ( errors_buffer) ;
606
624
}
607
625
}
608
626
}
@@ -654,8 +672,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
654
672
// region, which ensures it can be encoded in a `ClosureOutlivesRequirement`.
655
673
let lower_bound_plus = self . non_local_universal_upper_bound ( * lower_bound) ;
656
674
assert ! ( self . universal_regions. is_universal_region( lower_bound_plus) ) ;
657
- assert ! ( !self . universal_regions
658
- . is_local_free_region( lower_bound_plus) ) ;
675
+ assert ! (
676
+ !self
677
+ . universal_regions
678
+ . is_local_free_region( lower_bound_plus)
679
+ ) ;
659
680
660
681
propagated_outlives_requirements. push ( ClosureOutlivesRequirement {
661
682
subject,
@@ -768,7 +789,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
768
789
769
790
// Grow further to get smallest universal region known to
770
791
// creator.
771
- let non_local_lub = self . universal_regions . non_local_upper_bound ( lub) ;
792
+ let non_local_lub = self . universal_region_relations . non_local_upper_bound ( lub) ;
772
793
773
794
debug ! (
774
795
"non_local_universal_upper_bound: non_local_lub={:?}" ,
@@ -804,7 +825,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
804
825
let mut lub = self . universal_regions . fr_fn_body ;
805
826
let r_scc = self . constraint_sccs . scc ( r) ;
806
827
for ur in self . scc_values . universal_regions_outlived_by ( r_scc) {
807
- lub = self . universal_regions . postdom_upper_bound ( lub, ur) ;
828
+ lub = self . universal_region_relations . postdom_upper_bound ( lub, ur) ;
808
829
}
809
830
810
831
debug ! ( "universal_upper_bound: r={:?} lub={:?}" , r, lub) ;
@@ -872,7 +893,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
872
893
. all ( |r1| {
873
894
self . scc_values
874
895
. universal_regions_outlived_by ( sup_region_scc)
875
- . any ( |r2| self . universal_regions . outlives ( r2, r1) )
896
+ . any ( |r2| self . universal_region_relations . outlives ( r2, r1) )
876
897
} ) ;
877
898
878
899
if !universal_outlives {
@@ -887,7 +908,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
887
908
return true ;
888
909
}
889
910
890
- self . scc_values . contains_points ( sup_region_scc, sub_region_scc)
911
+ self . scc_values
912
+ . contains_points ( sup_region_scc, sub_region_scc)
891
913
}
892
914
893
915
/// Once regions have been propagated, this method is used to see
@@ -977,7 +999,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
977
999
// (because `fr` includes `end(o)`).
978
1000
for shorter_fr in self . scc_values . universal_regions_outlived_by ( longer_fr_scc) {
979
1001
// If it is known that `fr: o`, carry on.
980
- if self . universal_regions . outlives ( longer_fr, shorter_fr) {
1002
+ if self
1003
+ . universal_region_relations
1004
+ . outlives ( longer_fr, shorter_fr)
1005
+ {
981
1006
continue ;
982
1007
}
983
1008
@@ -991,14 +1016,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
991
1016
if let Some ( propagated_outlives_requirements) = propagated_outlives_requirements {
992
1017
// Shrink `fr` until we find a non-local region (if we do).
993
1018
// We'll call that `fr-` -- it's ever so slightly smaller than `fr`.
994
- if let Some ( fr_minus) = self . universal_regions . non_local_lower_bound ( longer_fr) {
1019
+ if let Some ( fr_minus) = self
1020
+ . universal_region_relations
1021
+ . non_local_lower_bound ( longer_fr)
1022
+ {
995
1023
debug ! ( "check_universal_region: fr_minus={:?}" , fr_minus) ;
996
1024
997
1025
// Grow `shorter_fr` until we find a non-local
998
1026
// region. (We always will.) We'll call that
999
1027
// `shorter_fr+` -- it's ever so slightly larger than
1000
1028
// `fr`.
1001
- let shorter_fr_plus = self . universal_regions . non_local_upper_bound ( shorter_fr) ;
1029
+ let shorter_fr_plus = self
1030
+ . universal_region_relations
1031
+ . non_local_upper_bound ( shorter_fr) ;
1002
1032
debug ! (
1003
1033
"check_universal_region: shorter_fr_plus={:?}" ,
1004
1034
shorter_fr_plus
@@ -1021,8 +1051,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1021
1051
// Note: in this case, we use the unapproximated regions
1022
1052
// to report the error. This gives better error messages
1023
1053
// in some cases.
1024
- self . report_error (
1025
- mir, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer) ;
1054
+ self . report_error ( mir, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer) ;
1026
1055
}
1027
1056
}
1028
1057
0 commit comments