@@ -32,10 +32,8 @@ pub(super) fn sub_types<'tcx>(
32
32
debug ! ( "sub_types(a={:?}, b={:?}, locations={:?})" , a, b, locations) ;
33
33
TypeRelating :: new (
34
34
infcx,
35
+ NllTypeRelatingDelegate :: new ( borrowck_context, locations, category) ,
35
36
ty:: Variance :: Covariant ,
36
- locations,
37
- category,
38
- borrowck_context,
39
37
ty:: List :: empty ( ) ,
40
38
) . relate ( & a, & b) ?;
41
39
Ok ( ( ) )
@@ -53,10 +51,8 @@ pub(super) fn eq_types<'tcx>(
53
51
debug ! ( "eq_types(a={:?}, b={:?}, locations={:?})" , a, b, locations) ;
54
52
TypeRelating :: new (
55
53
infcx,
54
+ NllTypeRelatingDelegate :: new ( borrowck_context, locations, category) ,
56
55
ty:: Variance :: Invariant ,
57
- locations,
58
- category,
59
- borrowck_context,
60
56
ty:: List :: empty ( ) ,
61
57
) . relate ( & a, & b) ?;
62
58
Ok ( ( ) )
@@ -90,17 +86,21 @@ pub(super) fn relate_type_and_user_type<'tcx>(
90
86
91
87
TypeRelating :: new (
92
88
infcx,
89
+ NllTypeRelatingDelegate :: new ( borrowck_context, locations, category) ,
93
90
v1,
94
- locations,
95
- category,
96
- borrowck_context,
97
91
b_variables,
98
92
) . relate ( & b_value, & a) ?;
99
93
Ok ( ( ) )
100
94
}
101
95
102
- struct TypeRelating < ' cx , ' bccx : ' cx , ' gcx : ' tcx , ' tcx : ' bccx > {
103
- infcx : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
96
+ struct TypeRelating < ' me , ' gcx : ' tcx , ' tcx : ' me , D >
97
+ where
98
+ D : TypeRelatingDelegate < ' tcx > ,
99
+ {
100
+ infcx : & ' me InferCtxt < ' me , ' gcx , ' tcx > ,
101
+
102
+ /// Callback to use when we deduce an outlives relationship
103
+ delegate : D ,
104
104
105
105
/// How are we relating `a` and `b`?
106
106
///
@@ -125,15 +125,6 @@ struct TypeRelating<'cx, 'bccx: 'cx, 'gcx: 'tcx, 'tcx: 'bccx> {
125
125
/// Same as `a_scopes`, but for the `b` type.
126
126
b_scopes : Vec < BoundRegionScope < ' tcx > > ,
127
127
128
- /// Where (and why) is this relation taking place?
129
- locations : Locations ,
130
-
131
- category : ConstraintCategory ,
132
-
133
- /// This will be `Some` when we are running the type check as part
134
- /// of NLL, and `None` if we are running a "sanity check".
135
- borrowck_context : Option < & ' cx mut BorrowCheckContext < ' bccx , ' tcx > > ,
136
-
137
128
/// As we execute, the type on the LHS *may* come from a canonical
138
129
/// source. In that case, we will sometimes find a constraint like
139
130
/// `?0 = B`, where `B` is a type from the RHS. The first time we
@@ -148,6 +139,54 @@ struct TypeRelating<'cx, 'bccx: 'cx, 'gcx: 'tcx, 'tcx: 'bccx> {
148
139
canonical_var_values : IndexVec < CanonicalVar , Option < Kind < ' tcx > > > ,
149
140
}
150
141
142
+ trait TypeRelatingDelegate < ' tcx > {
143
+ fn push_outlives ( & mut self , sup : ty:: Region < ' tcx > , sub : ty:: Region < ' tcx > ) ;
144
+ }
145
+
146
+ struct NllTypeRelatingDelegate < ' me , ' bccx : ' me , ' tcx : ' bccx > {
147
+ borrowck_context : Option < & ' me mut BorrowCheckContext < ' bccx , ' tcx > > ,
148
+
149
+ /// Where (and why) is this relation taking place?
150
+ locations : Locations ,
151
+
152
+ /// What category do we assign the resulting `'a: 'b` relationships?
153
+ category : ConstraintCategory ,
154
+ }
155
+
156
+ impl NllTypeRelatingDelegate < ' me , ' bccx , ' tcx > {
157
+ fn new (
158
+ borrowck_context : Option < & ' me mut BorrowCheckContext < ' bccx , ' tcx > > ,
159
+ locations : Locations ,
160
+ category : ConstraintCategory ,
161
+ ) -> Self {
162
+ Self {
163
+ borrowck_context,
164
+ locations,
165
+ category,
166
+ }
167
+ }
168
+ }
169
+
170
+ impl TypeRelatingDelegate < ' tcx > for NllTypeRelatingDelegate < ' _ , ' _ , ' tcx > {
171
+ fn push_outlives ( & mut self , sup : ty:: Region < ' tcx > , sub : ty:: Region < ' tcx > ) {
172
+ if let Some ( borrowck_context) = & mut self . borrowck_context {
173
+ let sub = borrowck_context. universal_regions . to_region_vid ( sub) ;
174
+ let sup = borrowck_context. universal_regions . to_region_vid ( sup) ;
175
+ borrowck_context
176
+ . constraints
177
+ . outlives_constraints
178
+ . push ( OutlivesConstraint {
179
+ sup,
180
+ sub,
181
+ locations : self . locations ,
182
+ category : self . category ,
183
+ } ) ;
184
+
185
+ // FIXME all facts!
186
+ }
187
+ }
188
+ }
189
+
151
190
#[ derive( Clone , Debug ) ]
152
191
struct ScopesAndKind < ' tcx > {
153
192
scopes : Vec < BoundRegionScope < ' tcx > > ,
@@ -162,23 +201,22 @@ struct BoundRegionScope<'tcx> {
162
201
#[ derive( Copy , Clone ) ]
163
202
struct UniversallyQuantified ( bool ) ;
164
203
165
- impl < ' cx , ' bccx , ' gcx , ' tcx > TypeRelating < ' cx , ' bccx , ' gcx , ' tcx > {
204
+ impl < ' me , ' gcx , ' tcx , D > TypeRelating < ' me , ' gcx , ' tcx , D >
205
+ where
206
+ D : TypeRelatingDelegate < ' tcx > ,
207
+ {
166
208
fn new (
167
- infcx : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
209
+ infcx : & ' me InferCtxt < ' me , ' gcx , ' tcx > ,
210
+ delegate : D ,
168
211
ambient_variance : ty:: Variance ,
169
- locations : Locations ,
170
- category : ConstraintCategory ,
171
- borrowck_context : Option < & ' cx mut BorrowCheckContext < ' bccx , ' tcx > > ,
172
212
canonical_var_infos : CanonicalVarInfos < ' tcx > ,
173
213
) -> Self {
174
214
let canonical_var_values = IndexVec :: from_elem_n ( None , canonical_var_infos. len ( ) ) ;
175
215
Self {
176
216
infcx,
217
+ delegate,
177
218
ambient_variance,
178
- borrowck_context,
179
- locations,
180
219
canonical_var_values,
181
- category,
182
220
a_scopes : vec ! [ ] ,
183
221
b_scopes : vec ! [ ] ,
184
222
}
@@ -259,21 +297,7 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
259
297
fn push_outlives ( & mut self , sup : ty:: Region < ' tcx > , sub : ty:: Region < ' tcx > ) {
260
298
debug ! ( "push_outlives({:?}: {:?})" , sup, sub) ;
261
299
262
- if let Some ( borrowck_context) = & mut self . borrowck_context {
263
- let sub = borrowck_context. universal_regions . to_region_vid ( sub) ;
264
- let sup = borrowck_context. universal_regions . to_region_vid ( sup) ;
265
- borrowck_context
266
- . constraints
267
- . outlives_constraints
268
- . push ( OutlivesConstraint {
269
- sup,
270
- sub,
271
- locations : self . locations ,
272
- category : self . category ,
273
- } ) ;
274
-
275
- // FIXME all facts!
276
- }
300
+ self . delegate . push_outlives ( sup, sub) ;
277
301
}
278
302
279
303
/// When we encounter a canonical variable `var` in the output,
@@ -325,10 +349,11 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
325
349
}
326
350
}
327
351
328
- impl < ' cx , ' bccx , ' gcx , ' tcx > TypeRelation < ' cx , ' gcx , ' tcx >
329
- for TypeRelating < ' cx , ' bccx , ' gcx , ' tcx >
352
+ impl < D > TypeRelation < ' me , ' gcx , ' tcx > for TypeRelating < ' me , ' gcx , ' tcx , D >
353
+ where
354
+ D : TypeRelatingDelegate < ' tcx > ,
330
355
{
331
- fn tcx ( & self ) -> TyCtxt < ' cx , ' gcx , ' tcx > {
356
+ fn tcx ( & self ) -> TyCtxt < ' me , ' gcx , ' tcx > {
332
357
self . infcx . tcx
333
358
}
334
359
@@ -534,15 +559,15 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx>
534
559
/// binder depth, and finds late-bound regions targeting the
535
560
/// `for<..`>. For each of those, it creates an entry in
536
561
/// `bound_region_scope`.
537
- struct ScopeInstantiator < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
538
- infcx : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
562
+ struct ScopeInstantiator < ' me , ' gcx : ' tcx , ' tcx : ' me > {
563
+ infcx : & ' me InferCtxt < ' me , ' gcx , ' tcx > ,
539
564
// The debruijn index of the scope we are instantiating.
540
565
target_index : ty:: DebruijnIndex ,
541
566
universally_quantified : UniversallyQuantified ,
542
- bound_region_scope : & ' cx mut BoundRegionScope < ' tcx > ,
567
+ bound_region_scope : & ' me mut BoundRegionScope < ' tcx > ,
543
568
}
544
569
545
- impl < ' cx , ' gcx , ' tcx > TypeVisitor < ' tcx > for ScopeInstantiator < ' cx , ' gcx , ' tcx > {
570
+ impl < ' me , ' gcx , ' tcx > TypeVisitor < ' tcx > for ScopeInstantiator < ' me , ' gcx , ' tcx > {
546
571
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & ty:: Binder < T > ) -> bool {
547
572
self . target_index . shift_in ( 1 ) ;
548
573
t. super_visit_with ( self ) ;
@@ -596,8 +621,11 @@ impl<'cx, 'gcx, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'cx, 'gcx, 'tcx> {
596
621
/// scopes.
597
622
///
598
623
/// [blog post]: https://is.gd/0hKvIr
599
- struct TypeGeneralizer < ' me , ' bccx : ' me , ' gcx : ' tcx , ' tcx : ' bccx > {
600
- type_rel : & ' me TypeRelating < ' me , ' bccx , ' gcx , ' tcx > ,
624
+ struct TypeGeneralizer < ' me , ' gcx : ' tcx , ' tcx : ' me , D >
625
+ where
626
+ D : TypeRelatingDelegate < ' tcx > + ' me ,
627
+ {
628
+ type_rel : & ' me TypeRelating < ' me , ' gcx , ' tcx , D > ,
601
629
602
630
/// After we generalize this type, we are going to relative it to
603
631
/// some other type. What will be the variance at this point?
@@ -608,7 +636,10 @@ struct TypeGeneralizer<'me, 'bccx: 'me, 'gcx: 'tcx, 'tcx: 'bccx> {
608
636
universe : ty:: UniverseIndex ,
609
637
}
610
638
611
- impl TypeRelation < ' me , ' gcx , ' tcx > for TypeGeneralizer < ' me , ' bbcx , ' gcx , ' tcx > {
639
+ impl < D > TypeRelation < ' me , ' gcx , ' tcx > for TypeGeneralizer < ' me , ' gcx , ' tcx , D >
640
+ where
641
+ D : TypeRelatingDelegate < ' tcx > ,
642
+ {
612
643
fn tcx ( & self ) -> TyCtxt < ' me , ' gcx , ' tcx > {
613
644
self . type_rel . infcx . tcx
614
645
}
0 commit comments