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,45 +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
- } )
187
- }
188
-
189
- /// Equates `expected` and `found` while structurally relating aliases.
190
- /// This should only be used inside of the next generation trait solver
191
- /// when relating rigid aliases.
192
- pub fn eq_structurally_relating_aliases < T > (
193
- self ,
194
- expected : T ,
195
- actual : T ,
196
- ) -> InferResult < ' tcx , ( ) >
197
- where
198
- T : ToTrace < ' tcx > ,
199
- {
200
- assert ! ( self . infcx. next_trait_solver( ) ) ;
201
- let mut fields = CombineFields :: new (
175
+ let mut op = TypeRelating :: new (
202
176
self . infcx ,
203
- ToTrace :: to_trace ( self . cause , expected , actual ) ,
177
+ trace ,
204
178
self . param_env ,
205
- DefineOpaqueTypes :: Yes ,
179
+ define_opaque_types,
180
+ StructurallyRelateAliases :: No ,
181
+ ty:: Invariant ,
206
182
) ;
207
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
208
- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
183
+ op . relate ( expected, actual) ?;
184
+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
209
185
}
210
186
211
187
pub fn relate < T > (
@@ -242,19 +218,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
242
218
where
243
219
T : Relate < TyCtxt < ' tcx > > ,
244
220
{
245
- let mut fields = CombineFields :: new (
221
+ let mut op = TypeRelating :: new (
246
222
self . infcx ,
247
223
TypeTrace :: dummy ( self . cause ) ,
248
224
self . param_env ,
249
225
DefineOpaqueTypes :: Yes ,
250
- ) ;
251
- fields. sub ( ) . relate_with_variance (
226
+ StructurallyRelateAliases :: No ,
252
227
variance,
253
- ty:: VarianceDiagInfo :: default ( ) ,
254
- expected,
255
- actual,
256
- ) ?;
257
- Ok ( fields. goals )
228
+ ) ;
229
+ op. relate ( expected, actual) ?;
230
+ Ok ( op. into_obligations ( ) . into_iter ( ) . map ( |o| o. into ( ) ) . collect ( ) )
258
231
}
259
232
260
233
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
@@ -266,60 +239,35 @@ impl<'a, 'tcx> At<'a, 'tcx> {
266
239
where
267
240
T : Relate < TyCtxt < ' tcx > > ,
268
241
{
269
- let mut fields = CombineFields :: new (
242
+ let mut op = TypeRelating :: new (
270
243
self . infcx ,
271
244
TypeTrace :: dummy ( self . cause ) ,
272
245
self . param_env ,
273
246
DefineOpaqueTypes :: Yes ,
247
+ StructurallyRelateAliases :: Yes ,
248
+ ty:: Invariant ,
274
249
) ;
275
- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
276
- Ok ( fields . goals )
250
+ op . relate ( expected, actual) ?;
251
+ Ok ( op . into_obligations ( ) . into_iter ( ) . map ( |o| o . into ( ) ) . collect ( ) )
277
252
}
278
253
279
254
/// Computes the least-upper-bound, or mutual supertype, of two
280
255
/// values. The order of the arguments doesn't matter, but since
281
256
/// this can result in an error (e.g., if asked to compute LUB of
282
257
/// u32 and i32), it is meaningful to call one of them the
283
258
/// "expected type".
284
- pub fn lub < T > (
285
- self ,
286
- define_opaque_types : DefineOpaqueTypes ,
287
- expected : T ,
288
- actual : T ,
289
- ) -> InferResult < ' tcx , T >
259
+ pub fn lub < T > ( self , expected : T , actual : T ) -> InferResult < ' tcx , T >
290
260
where
291
261
T : ToTrace < ' tcx > ,
292
262
{
293
- let mut fields = CombineFields :: new (
263
+ let mut op = LatticeOp :: new (
294
264
self . infcx ,
295
265
ToTrace :: to_trace ( self . cause , expected, actual) ,
296
266
self . param_env ,
297
- define_opaque_types,
298
- ) ;
299
- let value = fields. lub ( ) . relate ( expected, actual) ?;
300
- Ok ( InferOk { value, obligations : fields. into_obligations ( ) } )
301
- }
302
-
303
- /// Computes the greatest-lower-bound, or mutual subtype, of two
304
- /// values. As with `lub` order doesn't matter, except for error
305
- /// cases.
306
- pub fn glb < T > (
307
- self ,
308
- define_opaque_types : DefineOpaqueTypes ,
309
- expected : T ,
310
- actual : T ,
311
- ) -> InferResult < ' tcx , T >
312
- where
313
- T : ToTrace < ' tcx > ,
314
- {
315
- let mut fields = CombineFields :: new (
316
- self . infcx ,
317
- ToTrace :: to_trace ( self . cause , expected, actual) ,
318
- self . param_env ,
319
- define_opaque_types,
267
+ LatticeOpKind :: Lub ,
320
268
) ;
321
- let value = fields . glb ( ) . relate ( expected, actual) ?;
322
- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
269
+ let value = op . relate ( expected, actual) ?;
270
+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
323
271
}
324
272
}
325
273
0 commit comments