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
///
@@ -108,14 +109,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
108
109
where
109
110
T : ToTrace < ' tcx > ,
110
111
{
111
- let mut fields = CombineFields :: new (
112
+ let mut op = TypeRelating :: new (
112
113
self . infcx ,
113
114
ToTrace :: to_trace ( self . cause , expected, actual) ,
114
115
self . param_env ,
115
116
define_opaque_types,
117
+ StructurallyRelateAliases :: No ,
118
+ ty:: Contravariant ,
116
119
) ;
117
- fields . sup ( ) . relate ( expected, actual) ?;
118
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
120
+ op . relate ( expected, actual) ?;
121
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
119
122
}
120
123
121
124
/// Makes `expected <: actual`.
@@ -128,14 +131,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
128
131
where
129
132
T : ToTrace < ' tcx > ,
130
133
{
131
- let mut fields = CombineFields :: new (
134
+ let mut op = TypeRelating :: new (
132
135
self . infcx ,
133
136
ToTrace :: to_trace ( self . cause , expected, actual) ,
134
137
self . param_env ,
135
138
define_opaque_types,
139
+ StructurallyRelateAliases :: No ,
140
+ ty:: Covariant ,
136
141
) ;
137
- fields . sub ( ) . relate ( expected, actual) ?;
138
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
142
+ op . relate ( expected, actual) ?;
143
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
139
144
}
140
145
141
146
/// Makes `expected == actual`.
@@ -167,23 +172,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
167
172
where
168
173
T : Relate < TyCtxt < ' tcx > > ,
169
174
{
170
- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
171
- fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
172
- Ok ( InferOk {
173
- value : ( ) ,
174
- obligations : fields
175
- . goals
176
- . into_iter ( )
177
- . map ( |goal| {
178
- Obligation :: new (
179
- self . infcx . tcx ,
180
- fields. trace . cause . clone ( ) ,
181
- goal. param_env ,
182
- goal. predicate ,
183
- )
184
- } )
185
- . collect ( ) ,
186
- } )
175
+ let mut op = TypeRelating :: new (
176
+ self . infcx ,
177
+ trace,
178
+ self . param_env ,
179
+ define_opaque_types,
180
+ StructurallyRelateAliases :: No ,
181
+ ty:: Invariant ,
182
+ ) ;
183
+ op. relate ( expected, actual) ?;
184
+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
187
185
}
188
186
189
187
/// Equates `expected` and `found` while structurally relating aliases.
@@ -198,14 +196,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
198
196
T : ToTrace < ' tcx > ,
199
197
{
200
198
assert ! ( self . infcx. next_trait_solver( ) ) ;
201
- let mut fields = CombineFields :: new (
199
+ let mut op = TypeRelating :: new (
202
200
self . infcx ,
203
201
ToTrace :: to_trace ( self . cause , expected, actual) ,
204
202
self . param_env ,
205
203
DefineOpaqueTypes :: Yes ,
204
+ StructurallyRelateAliases :: Yes ,
205
+ ty:: Invariant ,
206
206
) ;
207
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
208
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
207
+ op . relate ( expected, actual) ?;
208
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
209
209
}
210
210
211
211
pub fn relate < T > (
@@ -242,19 +242,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
242
242
where
243
243
T : Relate < TyCtxt < ' tcx > > ,
244
244
{
245
- let mut fields = CombineFields :: new (
245
+ let mut op = TypeRelating :: new (
246
246
self . infcx ,
247
247
TypeTrace :: dummy ( self . cause ) ,
248
248
self . param_env ,
249
249
DefineOpaqueTypes :: Yes ,
250
- ) ;
251
- fields. sub ( ) . relate_with_variance (
250
+ StructurallyRelateAliases :: No ,
252
251
variance,
253
- ty:: VarianceDiagInfo :: default ( ) ,
254
- expected,
255
- actual,
256
- ) ?;
257
- Ok ( fields. goals )
252
+ ) ;
253
+ op. relate ( expected, actual) ?;
254
+ Ok ( op. into_obligations ( ) . into_iter ( ) . map ( |o| o. into ( ) ) . collect ( ) )
258
255
}
259
256
260
257
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
@@ -266,14 +263,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
266
263
where
267
264
T : Relate < TyCtxt < ' tcx > > ,
268
265
{
269
- let mut fields = CombineFields :: new (
266
+ let mut op = TypeRelating :: new (
270
267
self . infcx ,
271
268
TypeTrace :: dummy ( self . cause ) ,
272
269
self . param_env ,
273
270
DefineOpaqueTypes :: Yes ,
271
+ StructurallyRelateAliases :: Yes ,
272
+ ty:: Invariant ,
274
273
) ;
275
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
276
- Ok ( fields . goals )
274
+ op . relate ( expected, actual) ?;
275
+ Ok ( op . into_obligations ( ) . into_iter ( ) . map ( |o| o . into ( ) ) . collect ( ) )
277
276
}
278
277
279
278
/// Computes the least-upper-bound, or mutual supertype, of two
@@ -290,14 +289,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
290
289
where
291
290
T : ToTrace < ' tcx > ,
292
291
{
293
- let mut fields = CombineFields :: new (
292
+ let mut op = LatticeOp :: new (
294
293
self . infcx ,
295
294
ToTrace :: to_trace ( self . cause , expected, actual) ,
296
295
self . param_env ,
297
296
define_opaque_types,
297
+ LatticeOpKind :: Lub ,
298
298
) ;
299
- let value = fields . lub ( ) . relate ( expected, actual) ?;
300
- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
299
+ let value = op . relate ( expected, actual) ?;
300
+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
301
301
}
302
302
303
303
/// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -312,14 +312,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
312
312
where
313
313
T : ToTrace < ' tcx > ,
314
314
{
315
- let mut fields = CombineFields :: new (
315
+ let mut op = LatticeOp :: new (
316
316
self . infcx ,
317
317
ToTrace :: to_trace ( self . cause , expected, actual) ,
318
318
self . param_env ,
319
319
define_opaque_types,
320
+ LatticeOpKind :: Glb ,
320
321
) ;
321
- let value = fields . glb ( ) . relate ( expected, actual) ?;
322
- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
322
+ let value = op . relate ( expected, actual) ?;
323
+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
323
324
}
324
325
}
325
326
0 commit comments