@@ -49,7 +49,6 @@ pub struct At<'a, 'tcx> {
49
49
50
50
pub struct Trace < ' a , ' tcx > {
51
51
at : At < ' a , ' tcx > ,
52
- a_is_expected : bool ,
53
52
trace : TypeTrace < ' tcx > ,
54
53
}
55
54
@@ -106,23 +105,6 @@ pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
106
105
}
107
106
108
107
impl < ' a , ' tcx > At < ' a , ' tcx > {
109
- /// Makes `a <: b`, where `a` may or may not be expected.
110
- ///
111
- /// See [`At::trace_exp`] and [`Trace::sub`] for a version of
112
- /// this method that only requires `T: Relate<'tcx>`
113
- pub fn sub_exp < T > (
114
- self ,
115
- define_opaque_types : DefineOpaqueTypes ,
116
- a_is_expected : bool ,
117
- a : T ,
118
- b : T ,
119
- ) -> InferResult < ' tcx , ( ) >
120
- where
121
- T : ToTrace < ' tcx > ,
122
- {
123
- self . trace_exp ( a_is_expected, a, b) . sub ( define_opaque_types, a, b)
124
- }
125
-
126
108
/// Makes `actual <: expected`. For example, if type-checking a
127
109
/// call like `foo(x)`, where `foo: fn(i32)`, you might have
128
110
/// `sup(i32, x)`, since the "expected" type is the type that
@@ -139,7 +121,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
139
121
where
140
122
T : ToTrace < ' tcx > ,
141
123
{
142
- self . sub_exp ( define_opaque_types , false , actual, expected)
124
+ self . trace ( expected , actual) . sup ( define_opaque_types , expected, actual )
143
125
}
144
126
145
127
/// Makes `expected <: actual`.
@@ -155,24 +137,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
155
137
where
156
138
T : ToTrace < ' tcx > ,
157
139
{
158
- self . sub_exp ( define_opaque_types, true , expected, actual)
159
- }
160
-
161
- /// Makes `expected <: actual`.
162
- ///
163
- /// See [`At::trace_exp`] and [`Trace::eq`] for a version of
164
- /// this method that only requires `T: Relate<'tcx>`
165
- pub fn eq_exp < T > (
166
- self ,
167
- define_opaque_types : DefineOpaqueTypes ,
168
- a_is_expected : bool ,
169
- a : T ,
170
- b : T ,
171
- ) -> InferResult < ' tcx , ( ) >
172
- where
173
- T : ToTrace < ' tcx > ,
174
- {
175
- self . trace_exp ( a_is_expected, a, b) . eq ( define_opaque_types, a, b)
140
+ self . trace ( expected, actual) . sub ( define_opaque_types, expected, actual)
176
141
}
177
142
178
143
/// Makes `expected <: actual`.
@@ -261,48 +226,50 @@ impl<'a, 'tcx> At<'a, 'tcx> {
261
226
where
262
227
T : ToTrace < ' tcx > ,
263
228
{
264
- self . trace_exp ( true , expected, actual)
229
+ let trace = ToTrace :: to_trace ( self . cause , true , expected, actual) ;
230
+ Trace { at : self , trace }
265
231
}
232
+ }
266
233
267
- /// Like `trace`, but the expected value is determined by the
268
- /// boolean argument (if true, then the first argument `a` is the
269
- /// "expected" value).
270
- pub fn trace_exp < T > ( self , a_is_expected : bool , a : T , b : T ) -> Trace < ' a , ' tcx >
234
+ impl < ' a , ' tcx > Trace < ' a , ' tcx > {
235
+ /// Makes `a <: b`.
236
+ # [ instrument ( skip ( self ) , level = "debug" ) ]
237
+ pub fn sub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
271
238
where
272
- T : ToTrace < ' tcx > ,
239
+ T : Relate < ' tcx > ,
273
240
{
274
- let trace = ToTrace :: to_trace ( self . cause , a_is_expected, a, b) ;
275
- Trace { at : self , trace, a_is_expected }
241
+ let Trace { at, trace } = self ;
242
+ let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
243
+ fields
244
+ . sub ( )
245
+ . relate ( a, b)
246
+ . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
276
247
}
277
- }
278
248
279
- impl < ' a , ' tcx > Trace < ' a , ' tcx > {
280
- /// Makes `a <: b` where `a` may or may not be expected (if
281
- /// `a_is_expected` is true, then `a` is expected).
249
+ /// Makes `a :> b`.
282
250
#[ instrument( skip( self ) , level = "debug" ) ]
283
- pub fn sub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
251
+ pub fn sup < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
284
252
where
285
253
T : Relate < ' tcx > ,
286
254
{
287
- let Trace { at, trace, a_is_expected } = self ;
255
+ let Trace { at, trace } = self ;
288
256
let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
289
257
fields
290
- . sub ( a_is_expected )
258
+ . sup ( )
291
259
. relate ( a, b)
292
260
. map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
293
261
}
294
262
295
- /// Makes `a == b`; the expectation is set by the call to
296
- /// `trace()`.
263
+ /// Makes `a == b`.
297
264
#[ instrument( skip( self ) , level = "debug" ) ]
298
265
pub fn eq < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
299
266
where
300
267
T : Relate < ' tcx > ,
301
268
{
302
- let Trace { at, trace, a_is_expected } = self ;
269
+ let Trace { at, trace } = self ;
303
270
let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
304
271
fields
305
- . equate ( StructurallyRelateAliases :: No , a_is_expected )
272
+ . equate ( StructurallyRelateAliases :: No )
306
273
. relate ( a, b)
307
274
. map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
308
275
}
@@ -314,11 +281,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
314
281
where
315
282
T : Relate < ' tcx > ,
316
283
{
317
- let Trace { at, trace, a_is_expected } = self ;
284
+ let Trace { at, trace } = self ;
318
285
debug_assert ! ( at. infcx. next_trait_solver( ) ) ;
319
286
let mut fields = at. infcx . combine_fields ( trace, at. param_env , DefineOpaqueTypes :: No ) ;
320
287
fields
321
- . equate ( StructurallyRelateAliases :: Yes , a_is_expected )
288
+ . equate ( StructurallyRelateAliases :: Yes )
322
289
. relate ( a, b)
323
290
. map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
324
291
}
@@ -328,10 +295,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
328
295
where
329
296
T : Relate < ' tcx > ,
330
297
{
331
- let Trace { at, trace, a_is_expected } = self ;
298
+ let Trace { at, trace } = self ;
332
299
let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
333
300
fields
334
- . lub ( a_is_expected )
301
+ . lub ( )
335
302
. relate ( a, b)
336
303
. map ( move |t| InferOk { value : t, obligations : fields. obligations } )
337
304
}
@@ -341,10 +308,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
341
308
where
342
309
T : Relate < ' tcx > ,
343
310
{
344
- let Trace { at, trace, a_is_expected } = self ;
311
+ let Trace { at, trace } = self ;
345
312
let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
346
313
fields
347
- . glb ( a_is_expected )
314
+ . glb ( )
348
315
. relate ( a, b)
349
316
. map ( move |t| InferOk { value : t, obligations : fields. obligations } )
350
317
}
0 commit comments