25
25
//! sometimes useful when the types of `c` and `d` are not traceable
26
26
//! things. (That system should probably be refactored.)
27
27
28
+ use relate:: lattice:: { LatticeOp , LatticeOpKind } ;
28
29
use rustc_middle:: bug;
29
30
use rustc_middle:: ty:: { Const , ImplSubject } ;
30
31
31
32
use super :: * ;
33
+ use crate :: infer:: relate:: type_relating:: TypeRelating ;
32
34
use crate :: infer:: relate:: { Relate , StructurallyRelateAliases , TypeRelation } ;
33
- use crate :: traits:: Obligation ;
34
35
35
36
/// Whether we should define opaque types or just treat them opaquely.
36
37
///
@@ -109,14 +110,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109
110
where
110
111
T : ToTrace < ' tcx > ,
111
112
{
112
- let mut fields = CombineFields :: new (
113
+ let mut op = TypeRelating :: new (
113
114
self . infcx ,
114
115
ToTrace :: to_trace ( self . cause , expected, actual) ,
115
116
self . param_env ,
116
117
define_opaque_types,
118
+ StructurallyRelateAliases :: No ,
119
+ ty:: Contravariant ,
117
120
) ;
118
- fields . sup ( ) . relate ( expected, actual) ?;
119
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
121
+ op . relate ( expected, actual) ?;
122
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
120
123
}
121
124
122
125
/// Makes `expected <: actual`.
@@ -129,14 +132,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
129
132
where
130
133
T : ToTrace < ' tcx > ,
131
134
{
132
- let mut fields = CombineFields :: new (
135
+ let mut op = TypeRelating :: new (
133
136
self . infcx ,
134
137
ToTrace :: to_trace ( self . cause , expected, actual) ,
135
138
self . param_env ,
136
139
define_opaque_types,
140
+ StructurallyRelateAliases :: No ,
141
+ ty:: Covariant ,
137
142
) ;
138
- fields . sub ( ) . relate ( expected, actual) ?;
139
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
143
+ op . relate ( expected, actual) ?;
144
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
140
145
}
141
146
142
147
/// Makes `expected == actual`.
@@ -168,23 +173,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
168
173
where
169
174
T : Relate < TyCtxt < ' tcx > > ,
170
175
{
171
- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
172
- fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
173
- Ok ( InferOk {
174
- value : ( ) ,
175
- obligations : fields
176
- . goals
177
- . into_iter ( )
178
- . map ( |goal| {
179
- Obligation :: new (
180
- self . infcx . tcx ,
181
- fields. trace . cause . clone ( ) ,
182
- goal. param_env ,
183
- goal. predicate ,
184
- )
185
- } )
186
- . collect ( ) ,
187
- } )
176
+ let mut op = TypeRelating :: new (
177
+ self . infcx ,
178
+ trace,
179
+ self . param_env ,
180
+ define_opaque_types,
181
+ StructurallyRelateAliases :: No ,
182
+ ty:: Invariant ,
183
+ ) ;
184
+ op. relate ( expected, actual) ?;
185
+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
188
186
}
189
187
190
188
/// Equates `expected` and `found` while structurally relating aliases.
@@ -199,14 +197,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
199
197
T : ToTrace < ' tcx > ,
200
198
{
201
199
assert ! ( self . infcx. next_trait_solver( ) ) ;
202
- let mut fields = CombineFields :: new (
200
+ let mut op = TypeRelating :: new (
203
201
self . infcx ,
204
202
ToTrace :: to_trace ( self . cause , expected, actual) ,
205
203
self . param_env ,
206
204
DefineOpaqueTypes :: Yes ,
205
+ StructurallyRelateAliases :: Yes ,
206
+ ty:: Invariant ,
207
207
) ;
208
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
209
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
208
+ op . relate ( expected, actual) ?;
209
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
210
210
}
211
211
212
212
pub fn relate < T > (
@@ -243,19 +243,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
243
243
where
244
244
T : Relate < TyCtxt < ' tcx > > ,
245
245
{
246
- let mut fields = CombineFields :: new (
246
+ let mut op = TypeRelating :: new (
247
247
self . infcx ,
248
248
TypeTrace :: dummy ( self . cause ) ,
249
249
self . param_env ,
250
250
DefineOpaqueTypes :: Yes ,
251
- ) ;
252
- fields. sub ( ) . relate_with_variance (
251
+ StructurallyRelateAliases :: No ,
253
252
variance,
254
- ty:: VarianceDiagInfo :: default ( ) ,
255
- expected,
256
- actual,
257
- ) ?;
258
- Ok ( fields. goals )
253
+ ) ;
254
+ op. relate ( expected, actual) ?;
255
+ Ok ( op. into_obligations ( ) . into_iter ( ) . map ( |o| o. into ( ) ) . collect ( ) )
259
256
}
260
257
261
258
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
@@ -267,14 +264,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
267
264
where
268
265
T : Relate < TyCtxt < ' tcx > > ,
269
266
{
270
- let mut fields = CombineFields :: new (
267
+ let mut op = TypeRelating :: new (
271
268
self . infcx ,
272
269
TypeTrace :: dummy ( self . cause ) ,
273
270
self . param_env ,
274
271
DefineOpaqueTypes :: Yes ,
272
+ StructurallyRelateAliases :: Yes ,
273
+ ty:: Invariant ,
275
274
) ;
276
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
277
- Ok ( fields . goals )
275
+ op . relate ( expected, actual) ?;
276
+ Ok ( op . into_obligations ( ) . into_iter ( ) . map ( |o| o . into ( ) ) . collect ( ) )
278
277
}
279
278
280
279
/// Computes the least-upper-bound, or mutual supertype, of two
@@ -291,14 +290,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
291
290
where
292
291
T : ToTrace < ' tcx > ,
293
292
{
294
- let mut fields = CombineFields :: new (
293
+ let mut op = LatticeOp :: new (
295
294
self . infcx ,
296
295
ToTrace :: to_trace ( self . cause , expected, actual) ,
297
296
self . param_env ,
298
297
define_opaque_types,
298
+ LatticeOpKind :: Lub ,
299
299
) ;
300
- let value = fields . lub ( ) . relate ( expected, actual) ?;
301
- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
300
+ let value = op . relate ( expected, actual) ?;
301
+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
302
302
}
303
303
304
304
/// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -313,14 +313,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
313
313
where
314
314
T : ToTrace < ' tcx > ,
315
315
{
316
- let mut fields = CombineFields :: new (
316
+ let mut op = LatticeOp :: new (
317
317
self . infcx ,
318
318
ToTrace :: to_trace ( self . cause , expected, actual) ,
319
319
self . param_env ,
320
320
define_opaque_types,
321
+ LatticeOpKind :: Glb ,
321
322
) ;
322
- let value = fields . glb ( ) . relate ( expected, actual) ?;
323
- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
323
+ let value = op . relate ( expected, actual) ?;
324
+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
324
325
}
325
326
}
326
327
0 commit comments