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