@@ -48,11 +48,6 @@ pub struct At<'a, 'tcx> {
48
48
pub param_env : ty:: ParamEnv < ' tcx > ,
49
49
}
50
50
51
- pub struct Trace < ' a , ' tcx > {
52
- at : At < ' a , ' tcx > ,
53
- trace : TypeTrace < ' tcx > ,
54
- }
55
-
56
51
impl < ' tcx > InferCtxt < ' tcx > {
57
52
#[ inline]
58
53
pub fn at < ' a > (
@@ -109,9 +104,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109
104
/// call like `foo(x)`, where `foo: fn(i32)`, you might have
110
105
/// `sup(i32, x)`, since the "expected" type is the type that
111
106
/// appears in the signature.
112
- ///
113
- /// See [`At::trace`] and [`Trace::sub`] for a version of
114
- /// this method that only requires `T: Relate<'tcx>`
115
107
pub fn sup < T > (
116
108
self ,
117
109
define_opaque_types : DefineOpaqueTypes ,
@@ -121,13 +113,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
121
113
where
122
114
T : ToTrace < ' tcx > ,
123
115
{
124
- self . trace ( expected, actual) . sup ( define_opaque_types, expected, actual)
116
+ let mut fields = CombineFields :: new (
117
+ self . infcx ,
118
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
119
+ self . param_env ,
120
+ define_opaque_types,
121
+ ) ;
122
+ fields
123
+ . sup ( )
124
+ . relate ( expected, actual)
125
+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
125
126
}
126
127
127
128
/// Makes `expected <: actual`.
128
- ///
129
- /// See [`At::trace`] and [`Trace::sub`] for a version of
130
- /// this method that only requires `T: Relate<'tcx>`
131
129
pub fn sub < T > (
132
130
self ,
133
131
define_opaque_types : DefineOpaqueTypes ,
@@ -137,13 +135,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
137
135
where
138
136
T : ToTrace < ' tcx > ,
139
137
{
140
- self . trace ( expected, actual) . sub ( define_opaque_types, expected, actual)
138
+ let mut fields = CombineFields :: new (
139
+ self . infcx ,
140
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
141
+ self . param_env ,
142
+ define_opaque_types,
143
+ ) ;
144
+ fields
145
+ . sub ( )
146
+ . relate ( expected, actual)
147
+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
141
148
}
142
149
143
- /// Makes `expected <: actual`.
144
- ///
145
- /// See [`At::trace`] and [`Trace::eq`] for a version of
146
- /// this method that only requires `T: Relate<'tcx>`
150
+ /// Makes `expected == actual`.
147
151
pub fn eq < T > (
148
152
self ,
149
153
define_opaque_types : DefineOpaqueTypes ,
@@ -153,7 +157,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
153
157
where
154
158
T : ToTrace < ' tcx > ,
155
159
{
156
- self . trace ( expected, actual) . eq ( define_opaque_types, expected, actual)
160
+ let mut fields = CombineFields :: new (
161
+ self . infcx ,
162
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
163
+ self . param_env ,
164
+ define_opaque_types,
165
+ ) ;
166
+ fields
167
+ . equate ( StructurallyRelateAliases :: No )
168
+ . relate ( expected, actual)
169
+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
157
170
}
158
171
159
172
/// Equates `expected` and `found` while structurally relating aliases.
@@ -167,10 +180,17 @@ impl<'a, 'tcx> At<'a, 'tcx> {
167
180
where
168
181
T : ToTrace < ' tcx > ,
169
182
{
170
- self . trace ( expected, actual) . eq_structurally_relating_aliases (
171
- expected,
172
- actual,
173
- )
183
+ assert ! ( self . infcx. next_trait_solver( ) ) ;
184
+ let mut fields = CombineFields :: new (
185
+ self . infcx ,
186
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
187
+ self . param_env ,
188
+ DefineOpaqueTypes :: Yes ,
189
+ ) ;
190
+ fields
191
+ . equate ( StructurallyRelateAliases :: Yes )
192
+ . relate ( expected, actual)
193
+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
174
194
}
175
195
176
196
pub fn relate < T > (
@@ -202,9 +222,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
202
222
/// this can result in an error (e.g., if asked to compute LUB of
203
223
/// u32 and i32), it is meaningful to call one of them the
204
224
/// "expected type".
205
- ///
206
- /// See [`At::trace`] and [`Trace::lub`] for a version of
207
- /// this method that only requires `T: Relate<'tcx>`
208
225
pub fn lub < T > (
209
226
self ,
210
227
define_opaque_types : DefineOpaqueTypes ,
@@ -214,15 +231,21 @@ impl<'a, 'tcx> At<'a, 'tcx> {
214
231
where
215
232
T : ToTrace < ' tcx > ,
216
233
{
217
- self . trace ( expected, actual) . lub ( define_opaque_types, expected, actual)
234
+ let mut fields = CombineFields :: new (
235
+ self . infcx ,
236
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
237
+ self . param_env ,
238
+ define_opaque_types,
239
+ ) ;
240
+ fields
241
+ . lub ( )
242
+ . relate ( expected, actual)
243
+ . map ( |value| InferOk { value, obligations : fields. obligations } )
218
244
}
219
245
220
246
/// Computes the greatest-lower-bound, or mutual subtype, of two
221
247
/// values. As with `lub` order doesn't matter, except for error
222
248
/// cases.
223
- ///
224
- /// See [`At::trace`] and [`Trace::glb`] for a version of
225
- /// this method that only requires `T: Relate<'tcx>`
226
249
pub fn glb < T > (
227
250
self ,
228
251
define_opaque_types : DefineOpaqueTypes ,
@@ -232,105 +255,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
232
255
where
233
256
T : ToTrace < ' tcx > ,
234
257
{
235
- self . trace ( expected, actual) . glb ( define_opaque_types, expected, actual)
236
- }
237
-
238
- /// Sets the "trace" values that will be used for
239
- /// error-reporting, but doesn't actually perform any operation
240
- /// yet (this is useful when you want to set the trace using
241
- /// distinct values from those you wish to operate upon).
242
- pub fn trace < T > ( self , expected : T , actual : T ) -> Trace < ' a , ' tcx >
243
- where
244
- T : ToTrace < ' tcx > ,
245
- {
246
- let trace = ToTrace :: to_trace ( self . cause , true , expected, actual) ;
247
- Trace { at : self , trace }
248
- }
249
- }
250
-
251
- impl < ' a , ' tcx > Trace < ' a , ' tcx > {
252
- /// Makes `a <: b`.
253
- #[ instrument( skip( self ) , level = "debug" ) ]
254
- pub fn sub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
255
- where
256
- T : Relate < ' tcx > ,
257
- {
258
- let Trace { at, trace } = self ;
259
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
260
- fields
261
- . sub ( )
262
- . relate ( a, b)
263
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
264
- }
265
-
266
- /// Makes `a :> b`.
267
- #[ instrument( skip( self ) , level = "debug" ) ]
268
- pub fn sup < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
269
- where
270
- T : Relate < ' tcx > ,
271
- {
272
- let Trace { at, trace } = self ;
273
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
274
- fields
275
- . sup ( )
276
- . relate ( a, b)
277
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
278
- }
279
-
280
- /// Makes `a == b`.
281
- #[ instrument( skip( self ) , level = "debug" ) ]
282
- pub fn eq < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
283
- where
284
- T : Relate < ' tcx > ,
285
- {
286
- let Trace { at, trace } = self ;
287
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
288
- fields
289
- . equate ( StructurallyRelateAliases :: No )
290
- . relate ( a, b)
291
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
292
- }
293
-
294
- /// Equates `a` and `b` while structurally relating aliases. This should only
295
- /// be used inside of the next generation trait solver when relating rigid aliases.
296
- #[ instrument( skip( self ) , level = "debug" ) ]
297
- pub fn eq_structurally_relating_aliases < T > ( self , a : T , b : T ) -> InferResult < ' tcx , ( ) >
298
- where
299
- T : Relate < ' tcx > ,
300
- {
301
- let Trace { at, trace } = self ;
302
- debug_assert ! ( at. infcx. next_trait_solver( ) ) ;
303
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , DefineOpaqueTypes :: Yes ) ;
304
- fields
305
- . equate ( StructurallyRelateAliases :: Yes )
306
- . relate ( a, b)
307
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
308
- }
309
-
310
- #[ instrument( skip( self ) , level = "debug" ) ]
311
- pub fn lub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
312
- where
313
- T : Relate < ' tcx > ,
314
- {
315
- let Trace { at, trace } = self ;
316
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
317
- fields
318
- . lub ( )
319
- . relate ( a, b)
320
- . map ( move |t| InferOk { value : t, obligations : fields. obligations } )
321
- }
322
-
323
- #[ instrument( skip( self ) , level = "debug" ) ]
324
- pub fn glb < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
325
- where
326
- T : Relate < ' tcx > ,
327
- {
328
- let Trace { at, trace } = self ;
329
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
258
+ let mut fields = CombineFields :: new (
259
+ self . infcx ,
260
+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
261
+ self . param_env ,
262
+ define_opaque_types,
263
+ ) ;
330
264
fields
331
265
. glb ( )
332
- . relate ( a , b )
333
- . map ( move |t | InferOk { value : t , obligations : fields. obligations } )
266
+ . relate ( expected , actual )
267
+ . map ( |value | InferOk { value, obligations : fields. obligations } )
334
268
}
335
269
}
336
270
0 commit comments