@@ -44,49 +44,48 @@ pub struct RegionInferenceContext<'tcx> {
44
44
/// variables are identified by their index (`RegionVid`). The
45
45
/// definition contains information about where the region came
46
46
/// from as well as its final inferred value.
47
- pub ( in crate :: borrow_check ) definitions : IndexVec < RegionVid , RegionDefinition < ' tcx > > ,
47
+ definitions : IndexVec < RegionVid , RegionDefinition < ' tcx > > ,
48
48
49
49
/// The liveness constraints added to each region. For most
50
50
/// regions, these start out empty and steadily grow, though for
51
51
/// each universally quantified region R they start out containing
52
52
/// the entire CFG and `end(R)`.
53
- pub ( in crate :: borrow_check ) liveness_constraints : LivenessValues < RegionVid > ,
53
+ liveness_constraints : LivenessValues < RegionVid > ,
54
54
55
55
/// The outlives constraints computed by the type-check.
56
- pub ( in crate :: borrow_check ) constraints : Rc < OutlivesConstraintSet > ,
56
+ constraints : Rc < OutlivesConstraintSet > ,
57
57
58
58
/// The constraint-set, but in graph form, making it easy to traverse
59
59
/// the constraints adjacent to a particular region. Used to construct
60
60
/// the SCC (see `constraint_sccs`) and for error reporting.
61
- pub ( in crate :: borrow_check ) constraint_graph : Rc < NormalConstraintGraph > ,
61
+ constraint_graph : Rc < NormalConstraintGraph > ,
62
62
63
63
/// The SCC computed from `constraints` and the constraint
64
64
/// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
65
65
/// compute the values of each region.
66
- pub ( in crate :: borrow_check ) constraint_sccs : Rc < Sccs < RegionVid , ConstraintSccIndex > > ,
66
+ constraint_sccs : Rc < Sccs < RegionVid , ConstraintSccIndex > > ,
67
67
68
68
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B`
69
69
/// exists if `B: A`. Computed lazilly.
70
- pub ( in crate :: borrow_check ) rev_constraint_graph : Option < Rc < VecGraph < ConstraintSccIndex > > > ,
70
+ rev_constraint_graph : Option < Rc < VecGraph < ConstraintSccIndex > > > ,
71
71
72
72
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
73
- pub ( in crate :: borrow_check) member_constraints :
74
- Rc < MemberConstraintSet < ' tcx , ConstraintSccIndex > > ,
73
+ member_constraints : Rc < MemberConstraintSet < ' tcx , ConstraintSccIndex > > ,
75
74
76
75
/// Records the member constraints that we applied to each scc.
77
76
/// This is useful for error reporting. Once constraint
78
77
/// propagation is done, this vector is sorted according to
79
78
/// `member_region_scc`.
80
- pub ( in crate :: borrow_check ) member_constraints_applied : Vec < AppliedMemberConstraint > ,
79
+ member_constraints_applied : Vec < AppliedMemberConstraint > ,
81
80
82
81
/// Map closure bounds to a `Span` that should be used for error reporting.
83
- pub ( in crate :: borrow_check ) closure_bounds_mapping :
82
+ closure_bounds_mapping :
84
83
FxHashMap < Location , FxHashMap < ( RegionVid , RegionVid ) , ( ConstraintCategory , Span ) > > ,
85
84
86
85
/// Contains the minimum universe of any variable within the same
87
86
/// SCC. We will ensure that no SCC contains values that are not
88
87
/// visible from this index.
89
- pub ( in crate :: borrow_check ) scc_universes : IndexVec < ConstraintSccIndex , ty:: UniverseIndex > ,
88
+ scc_universes : IndexVec < ConstraintSccIndex , ty:: UniverseIndex > ,
90
89
91
90
/// Contains a "representative" from each SCC. This will be the
92
91
/// minimal RegionVid belonging to that universe. It is used as a
@@ -95,23 +94,23 @@ pub struct RegionInferenceContext<'tcx> {
95
94
/// of its SCC and be sure that -- if they have the same repr --
96
95
/// they *must* be equal (though not having the same repr does not
97
96
/// mean they are unequal).
98
- pub ( in crate :: borrow_check ) scc_representatives : IndexVec < ConstraintSccIndex , ty:: RegionVid > ,
97
+ scc_representatives : IndexVec < ConstraintSccIndex , ty:: RegionVid > ,
99
98
100
99
/// The final inferred values of the region variables; we compute
101
100
/// one value per SCC. To get the value for any given *region*,
102
101
/// you first find which scc it is a part of.
103
- pub ( in crate :: borrow_check ) scc_values : RegionValues < ConstraintSccIndex > ,
102
+ scc_values : RegionValues < ConstraintSccIndex > ,
104
103
105
104
/// Type constraints that we check after solving.
106
- pub ( in crate :: borrow_check ) type_tests : Vec < TypeTest < ' tcx > > ,
105
+ type_tests : Vec < TypeTest < ' tcx > > ,
107
106
108
107
/// Information about the universally quantified regions in scope
109
108
/// on this function.
110
- pub ( in crate :: borrow_check ) universal_regions : Rc < UniversalRegions < ' tcx > > ,
109
+ universal_regions : Rc < UniversalRegions < ' tcx > > ,
111
110
112
111
/// Information about how the universally quantified regions in
113
112
/// scope on this function relate to one another.
114
- pub ( in crate :: borrow_check ) universal_region_relations : Rc < UniversalRegionRelations < ' tcx > > ,
113
+ universal_region_relations : Rc < UniversalRegionRelations < ' tcx > > ,
115
114
}
116
115
117
116
/// Each time that `apply_member_constraint` is successful, it appends
@@ -1840,6 +1839,38 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1840
1839
. unwrap ( )
1841
1840
}
1842
1841
1842
+ /// Get the region outlived by `longer_fr` and live at `element`.
1843
+ crate fn region_from_element ( & self , longer_fr : RegionVid , element : RegionElement ) -> RegionVid {
1844
+ match element {
1845
+ RegionElement :: Location ( l) => self . find_sub_region_live_at ( longer_fr, l) ,
1846
+ RegionElement :: RootUniversalRegion ( r) => r,
1847
+ RegionElement :: PlaceholderRegion ( error_placeholder) => self
1848
+ . definitions
1849
+ . iter_enumerated ( )
1850
+ . filter_map ( |( r, definition) | match definition. origin {
1851
+ NLLRegionVariableOrigin :: Placeholder ( p) if p == error_placeholder => Some ( r) ,
1852
+ _ => None ,
1853
+ } )
1854
+ . next ( )
1855
+ . unwrap ( ) ,
1856
+ }
1857
+ }
1858
+
1859
+ /// Get the region definition of `r`.
1860
+ crate fn region_definition ( & self , r : RegionVid ) -> & RegionDefinition < ' tcx > {
1861
+ & self . definitions [ r]
1862
+ }
1863
+
1864
+ /// Check if the SCC of `r` contains `upper`.
1865
+ crate fn upper_bound_in_region_scc ( & self , r : RegionVid , upper : RegionVid ) -> bool {
1866
+ let r_scc = self . constraint_sccs . scc ( r) ;
1867
+ self . scc_values . contains ( r_scc, upper)
1868
+ }
1869
+
1870
+ crate fn universal_regions ( & self ) -> Rc < UniversalRegions < ' tcx > > {
1871
+ self . universal_regions . clone ( )
1872
+ }
1873
+
1843
1874
/// Tries to find the best constraint to blame for the fact that
1844
1875
/// `R: from_region`, where `R` is some region that meets
1845
1876
/// `target_test`. This works by following the constraint graph,
0 commit comments