@@ -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,40 @@ 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 } )
170
+ }
171
+
172
+ /// Equates `expected` and `found` while structurally relating aliases.
173
+ /// This should only be used inside of the next generation trait solver
174
+ /// when relating rigid aliases.
175
+ pub fn eq_structurally_relating_aliases < T > (
176
+ self ,
177
+ expected : T ,
178
+ actual : T ,
179
+ ) -> InferResult < ' tcx , ( ) >
180
+ where
181
+ T : ToTrace < ' tcx > ,
182
+ {
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 } )
157
194
}
158
195
159
196
pub fn relate < T > (
@@ -185,9 +222,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
185
222
/// this can result in an error (e.g., if asked to compute LUB of
186
223
/// u32 and i32), it is meaningful to call one of them the
187
224
/// "expected type".
188
- ///
189
- /// See [`At::trace`] and [`Trace::lub`] for a version of
190
- /// this method that only requires `T: Relate<'tcx>`
191
225
pub fn lub < T > (
192
226
self ,
193
227
define_opaque_types : DefineOpaqueTypes ,
@@ -197,15 +231,21 @@ impl<'a, 'tcx> At<'a, 'tcx> {
197
231
where
198
232
T : ToTrace < ' tcx > ,
199
233
{
200
- 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 } )
201
244
}
202
245
203
246
/// Computes the greatest-lower-bound, or mutual subtype, of two
204
247
/// values. As with `lub` order doesn't matter, except for error
205
248
/// cases.
206
- ///
207
- /// See [`At::trace`] and [`Trace::glb`] for a version of
208
- /// this method that only requires `T: Relate<'tcx>`
209
249
pub fn glb < T > (
210
250
self ,
211
251
define_opaque_types : DefineOpaqueTypes ,
@@ -215,105 +255,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
215
255
where
216
256
T : ToTrace < ' tcx > ,
217
257
{
218
- self . trace ( expected, actual) . glb ( define_opaque_types, expected, actual)
219
- }
220
-
221
- /// Sets the "trace" values that will be used for
222
- /// error-reporting, but doesn't actually perform any operation
223
- /// yet (this is useful when you want to set the trace using
224
- /// distinct values from those you wish to operate upon).
225
- pub fn trace < T > ( self , expected : T , actual : T ) -> Trace < ' a , ' tcx >
226
- where
227
- T : ToTrace < ' tcx > ,
228
- {
229
- let trace = ToTrace :: to_trace ( self . cause , true , expected, actual) ;
230
- Trace { at : self , trace }
231
- }
232
- }
233
-
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 , ( ) >
238
- where
239
- T : Relate < ' tcx > ,
240
- {
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 } )
247
- }
248
-
249
- /// Makes `a :> b`.
250
- #[ instrument( skip( self ) , level = "debug" ) ]
251
- pub fn sup < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
252
- where
253
- T : Relate < ' tcx > ,
254
- {
255
- let Trace { at, trace } = self ;
256
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
257
- fields
258
- . sup ( )
259
- . relate ( a, b)
260
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
261
- }
262
-
263
- /// Makes `a == b`.
264
- #[ instrument( skip( self ) , level = "debug" ) ]
265
- pub fn eq < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
266
- where
267
- T : Relate < ' tcx > ,
268
- {
269
- let Trace { at, trace } = self ;
270
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
271
- fields
272
- . equate ( StructurallyRelateAliases :: No )
273
- . relate ( a, b)
274
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
275
- }
276
-
277
- /// Equates `a` and `b` while structurally relating aliases. This should only
278
- /// be used inside of the next generation trait solver when relating rigid aliases.
279
- #[ instrument( skip( self ) , level = "debug" ) ]
280
- pub fn eq_structurally_relating_aliases < T > ( self , a : T , b : T ) -> InferResult < ' tcx , ( ) >
281
- where
282
- T : Relate < ' tcx > ,
283
- {
284
- let Trace { at, trace } = self ;
285
- debug_assert ! ( at. infcx. next_trait_solver( ) ) ;
286
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , DefineOpaqueTypes :: Yes ) ;
287
- fields
288
- . equate ( StructurallyRelateAliases :: Yes )
289
- . relate ( a, b)
290
- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
291
- }
292
-
293
- #[ instrument( skip( self ) , level = "debug" ) ]
294
- pub fn lub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
295
- where
296
- T : Relate < ' tcx > ,
297
- {
298
- let Trace { at, trace } = self ;
299
- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
300
- fields
301
- . lub ( )
302
- . relate ( a, b)
303
- . map ( move |t| InferOk { value : t, obligations : fields. obligations } )
304
- }
305
-
306
- #[ instrument( skip( self ) , level = "debug" ) ]
307
- pub fn glb < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
308
- where
309
- T : Relate < ' tcx > ,
310
- {
311
- let Trace { at, trace } = self ;
312
- 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
+ ) ;
313
264
fields
314
265
. glb ( )
315
- . relate ( a , b )
316
- . map ( move |t | InferOk { value : t , obligations : fields. obligations } )
266
+ . relate ( expected , actual )
267
+ . map ( |value | InferOk { value, obligations : fields. obligations } )
317
268
}
318
269
}
319
270
0 commit comments