@@ -52,12 +52,10 @@ pub struct OutlivesEnvironment<'tcx> {
52
52
region_bound_pairs : RegionBoundPairs < ' tcx > ,
53
53
}
54
54
55
- /// Builder of OutlivesEnvironment. Use this structure if you need to add more outlives
56
- /// bounds than `explicit_outlives_bounds(param_env)`.
57
- pub struct OutlivesEnvironmentBuilder < ' tcx > {
58
- pub param_env : ty:: ParamEnv < ' tcx > ,
55
+ /// Builder of OutlivesEnvironment.
56
+ struct OutlivesEnvironmentBuilder < ' tcx > {
57
+ param_env : ty:: ParamEnv < ' tcx > ,
59
58
region_relation : TransitiveRelationBuilder < Region < ' tcx > > ,
60
-
61
59
region_bound_pairs : RegionBoundPairs < ' tcx > ,
62
60
}
63
61
@@ -69,7 +67,7 @@ pub type RegionBoundPairs<'tcx> =
69
67
70
68
impl < ' tcx > OutlivesEnvironment < ' tcx > {
71
69
/// Create a builder using `ParamEnv` and add explicit outlives bounds into it.
72
- pub fn builder ( param_env : ty:: ParamEnv < ' tcx > ) -> OutlivesEnvironmentBuilder < ' tcx > {
70
+ fn builder ( param_env : ty:: ParamEnv < ' tcx > ) -> OutlivesEnvironmentBuilder < ' tcx > {
73
71
let mut builder = OutlivesEnvironmentBuilder {
74
72
param_env,
75
73
region_relation : Default :: default ( ) ,
@@ -87,6 +85,17 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
87
85
Self :: builder ( param_env) . build ( )
88
86
}
89
87
88
+ /// Create a new `OutlivesEnvironment` with extra outlives bounds.
89
+ pub fn with_bounds < ' a > (
90
+ param_env : ty:: ParamEnv < ' tcx > ,
91
+ infcx : Option < & InferCtxt < ' a , ' tcx > > ,
92
+ extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
93
+ ) -> Self {
94
+ let mut builder = Self :: builder ( param_env) ;
95
+ builder. add_outlives_bounds ( infcx, extra_bounds) ;
96
+ builder. build ( )
97
+ }
98
+
90
99
/// Borrows current value of the `free_region_map`.
91
100
pub fn free_region_map ( & self ) -> & FreeRegionMap < ' tcx > {
92
101
& self . free_region_map
@@ -108,26 +117,14 @@ impl<'a, 'tcx> OutlivesEnvironmentBuilder<'tcx> {
108
117
}
109
118
}
110
119
111
- // Record that `'sup:'sub`. Or, put another way, `'sub <= 'sup`.
112
- // (with the exception that `'static: 'x` is not notable)
113
- fn relate_regions ( & mut self , sub : Region < ' tcx > , sup : Region < ' tcx > ) {
114
- debug ! ( "relate_regions(sub={:?}, sup={:?})" , sub, sup) ;
115
- if sub. is_free_or_static ( ) && sup. is_free ( ) {
116
- self . region_relation . add ( sub, sup)
117
- }
118
- }
119
-
120
120
/// Processes outlives bounds that are known to hold, whether from implied or other sources.
121
121
///
122
122
/// The `infcx` parameter is optional; if the implied bounds may
123
123
/// contain inference variables, it must be supplied, in which
124
124
/// case we will register "givens" on the inference context. (See
125
125
/// `RegionConstraintData`.)
126
- pub fn add_outlives_bounds < I > (
127
- & mut self ,
128
- infcx : Option < & InferCtxt < ' a , ' tcx > > ,
129
- outlives_bounds : I ,
130
- ) where
126
+ fn add_outlives_bounds < I > ( & mut self , infcx : Option < & InferCtxt < ' a , ' tcx > > , outlives_bounds : I )
127
+ where
131
128
I : IntoIterator < Item = OutlivesBound < ' tcx > > ,
132
129
{
133
130
// Record relationships such as `T:'x` that don't go into the
@@ -159,7 +156,9 @@ impl<'a, 'tcx> OutlivesEnvironmentBuilder<'tcx> {
159
156
// system to be more general and to make use
160
157
// of *every* relationship that arises here,
161
158
// but presently we do not.)
162
- self . relate_regions ( r_a, r_b) ;
159
+ if r_a. is_free_or_static ( ) && r_b. is_free ( ) {
160
+ self . region_relation . add ( r_a, r_b)
161
+ }
163
162
}
164
163
}
165
164
}
0 commit comments