@@ -92,12 +92,7 @@ impl<'tcx> InferCtxt<'tcx> {
92
92
}
93
93
94
94
pub trait ToTrace < ' tcx > : Relate < TyCtxt < ' tcx > > + Copy {
95
- fn to_trace (
96
- cause : & ObligationCause < ' tcx > ,
97
- a_is_expected : bool ,
98
- a : Self ,
99
- b : Self ,
100
- ) -> TypeTrace < ' tcx > ;
95
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > ;
101
96
}
102
97
103
98
impl < ' a , ' tcx > At < ' a , ' tcx > {
@@ -116,7 +111,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
116
111
{
117
112
let mut fields = CombineFields :: new (
118
113
self . infcx ,
119
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
114
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
120
115
self . param_env ,
121
116
define_opaque_types,
122
117
) ;
@@ -136,7 +131,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
136
131
{
137
132
let mut fields = CombineFields :: new (
138
133
self . infcx ,
139
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
134
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
140
135
self . param_env ,
141
136
define_opaque_types,
142
137
) ;
@@ -154,12 +149,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
154
149
where
155
150
T : ToTrace < ' tcx > ,
156
151
{
157
- let mut fields = CombineFields :: new (
158
- self . infcx ,
159
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
160
- self . param_env ,
152
+ self . eq_trace (
161
153
define_opaque_types,
162
- ) ;
154
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
155
+ expected,
156
+ actual,
157
+ )
158
+ }
159
+
160
+ /// Makes `expected == actual`.
161
+ pub fn eq_trace < T > (
162
+ self ,
163
+ define_opaque_types : DefineOpaqueTypes ,
164
+ trace : TypeTrace < ' tcx > ,
165
+ expected : T ,
166
+ actual : T ,
167
+ ) -> InferResult < ' tcx , ( ) >
168
+ where
169
+ T : Relate < TyCtxt < ' tcx > > ,
170
+ {
171
+ let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
163
172
fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
164
173
Ok ( InferOk {
165
174
value : ( ) ,
@@ -192,7 +201,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
192
201
assert ! ( self . infcx. next_trait_solver( ) ) ;
193
202
let mut fields = CombineFields :: new (
194
203
self . infcx ,
195
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
204
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
196
205
self . param_env ,
197
206
DefineOpaqueTypes :: Yes ,
198
207
) ;
@@ -284,7 +293,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
284
293
{
285
294
let mut fields = CombineFields :: new (
286
295
self . infcx ,
287
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
296
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
288
297
self . param_env ,
289
298
define_opaque_types,
290
299
) ;
@@ -306,7 +315,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
306
315
{
307
316
let mut fields = CombineFields :: new (
308
317
self . infcx ,
309
- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
318
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
310
319
self . param_env ,
311
320
define_opaque_types,
312
321
) ;
@@ -316,18 +325,13 @@ impl<'a, 'tcx> At<'a, 'tcx> {
316
325
}
317
326
318
327
impl < ' tcx > ToTrace < ' tcx > for ImplSubject < ' tcx > {
319
- fn to_trace (
320
- cause : & ObligationCause < ' tcx > ,
321
- a_is_expected : bool ,
322
- a : Self ,
323
- b : Self ,
324
- ) -> TypeTrace < ' tcx > {
328
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
325
329
match ( a, b) {
326
330
( ImplSubject :: Trait ( trait_ref_a) , ImplSubject :: Trait ( trait_ref_b) ) => {
327
- ToTrace :: to_trace ( cause, a_is_expected , trait_ref_a, trait_ref_b)
331
+ ToTrace :: to_trace ( cause, trait_ref_a, trait_ref_b)
328
332
}
329
333
( ImplSubject :: Inherent ( ty_a) , ImplSubject :: Inherent ( ty_b) ) => {
330
- ToTrace :: to_trace ( cause, a_is_expected , ty_a, ty_b)
334
+ ToTrace :: to_trace ( cause, ty_a, ty_b)
331
335
}
332
336
( ImplSubject :: Trait ( _) , ImplSubject :: Inherent ( _) )
333
337
| ( ImplSubject :: Inherent ( _) , ImplSubject :: Trait ( _) ) => {
@@ -338,65 +342,45 @@ impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
338
342
}
339
343
340
344
impl < ' tcx > ToTrace < ' tcx > for Ty < ' tcx > {
341
- fn to_trace (
342
- cause : & ObligationCause < ' tcx > ,
343
- a_is_expected : bool ,
344
- a : Self ,
345
- b : Self ,
346
- ) -> TypeTrace < ' tcx > {
345
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
347
346
TypeTrace {
348
347
cause : cause. clone ( ) ,
349
- values : ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a. into ( ) , b. into ( ) ) ) ,
348
+ values : ValuePairs :: Terms ( ExpectedFound :: new ( true , a. into ( ) , b. into ( ) ) ) ,
350
349
}
351
350
}
352
351
}
353
352
354
353
impl < ' tcx > ToTrace < ' tcx > for ty:: Region < ' tcx > {
355
- fn to_trace (
356
- cause : & ObligationCause < ' tcx > ,
357
- a_is_expected : bool ,
358
- a : Self ,
359
- b : Self ,
360
- ) -> TypeTrace < ' tcx > {
354
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
361
355
TypeTrace {
362
356
cause : cause. clone ( ) ,
363
- values : ValuePairs :: Regions ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
357
+ values : ValuePairs :: Regions ( ExpectedFound :: new ( true , a, b) ) ,
364
358
}
365
359
}
366
360
}
367
361
368
362
impl < ' tcx > ToTrace < ' tcx > for Const < ' tcx > {
369
- fn to_trace (
370
- cause : & ObligationCause < ' tcx > ,
371
- a_is_expected : bool ,
372
- a : Self ,
373
- b : Self ,
374
- ) -> TypeTrace < ' tcx > {
363
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
375
364
TypeTrace {
376
365
cause : cause. clone ( ) ,
377
- values : ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a. into ( ) , b. into ( ) ) ) ,
366
+ values : ValuePairs :: Terms ( ExpectedFound :: new ( true , a. into ( ) , b. into ( ) ) ) ,
378
367
}
379
368
}
380
369
}
381
370
382
371
impl < ' tcx > ToTrace < ' tcx > for ty:: GenericArg < ' tcx > {
383
- fn to_trace (
384
- cause : & ObligationCause < ' tcx > ,
385
- a_is_expected : bool ,
386
- a : Self ,
387
- b : Self ,
388
- ) -> TypeTrace < ' tcx > {
372
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
389
373
TypeTrace {
390
374
cause : cause. clone ( ) ,
391
375
values : match ( a. unpack ( ) , b. unpack ( ) ) {
392
376
( GenericArgKind :: Lifetime ( a) , GenericArgKind :: Lifetime ( b) ) => {
393
- ValuePairs :: Regions ( ExpectedFound :: new ( a_is_expected , a, b) )
377
+ ValuePairs :: Regions ( ExpectedFound :: new ( true , a, b) )
394
378
}
395
379
( GenericArgKind :: Type ( a) , GenericArgKind :: Type ( b) ) => {
396
- ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a. into ( ) , b. into ( ) ) )
380
+ ValuePairs :: Terms ( ExpectedFound :: new ( true , a. into ( ) , b. into ( ) ) )
397
381
}
398
382
( GenericArgKind :: Const ( a) , GenericArgKind :: Const ( b) ) => {
399
- ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a. into ( ) , b. into ( ) ) )
383
+ ValuePairs :: Terms ( ExpectedFound :: new ( true , a. into ( ) , b. into ( ) ) )
400
384
}
401
385
402
386
(
@@ -419,72 +403,47 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
419
403
}
420
404
421
405
impl < ' tcx > ToTrace < ' tcx > for ty:: Term < ' tcx > {
422
- fn to_trace (
423
- cause : & ObligationCause < ' tcx > ,
424
- a_is_expected : bool ,
425
- a : Self ,
426
- b : Self ,
427
- ) -> TypeTrace < ' tcx > {
406
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
428
407
TypeTrace {
429
408
cause : cause. clone ( ) ,
430
- values : ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
409
+ values : ValuePairs :: Terms ( ExpectedFound :: new ( true , a, b) ) ,
431
410
}
432
411
}
433
412
}
434
413
435
414
impl < ' tcx > ToTrace < ' tcx > for ty:: TraitRef < ' tcx > {
436
- fn to_trace (
437
- cause : & ObligationCause < ' tcx > ,
438
- a_is_expected : bool ,
439
- a : Self ,
440
- b : Self ,
441
- ) -> TypeTrace < ' tcx > {
415
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
442
416
TypeTrace {
443
417
cause : cause. clone ( ) ,
444
- values : ValuePairs :: TraitRefs ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
418
+ values : ValuePairs :: TraitRefs ( ExpectedFound :: new ( true , a, b) ) ,
445
419
}
446
420
}
447
421
}
448
422
449
423
impl < ' tcx > ToTrace < ' tcx > for ty:: AliasTy < ' tcx > {
450
- fn to_trace (
451
- cause : & ObligationCause < ' tcx > ,
452
- a_is_expected : bool ,
453
- a : Self ,
454
- b : Self ,
455
- ) -> TypeTrace < ' tcx > {
424
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
456
425
TypeTrace {
457
426
cause : cause. clone ( ) ,
458
- values : ValuePairs :: Aliases ( ExpectedFound :: new ( a_is_expected , a. into ( ) , b. into ( ) ) ) ,
427
+ values : ValuePairs :: Aliases ( ExpectedFound :: new ( true , a. into ( ) , b. into ( ) ) ) ,
459
428
}
460
429
}
461
430
}
462
431
463
432
impl < ' tcx > ToTrace < ' tcx > for ty:: AliasTerm < ' tcx > {
464
- fn to_trace (
465
- cause : & ObligationCause < ' tcx > ,
466
- a_is_expected : bool ,
467
- a : Self ,
468
- b : Self ,
469
- ) -> TypeTrace < ' tcx > {
433
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
470
434
TypeTrace {
471
435
cause : cause. clone ( ) ,
472
- values : ValuePairs :: Aliases ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
436
+ values : ValuePairs :: Aliases ( ExpectedFound :: new ( true , a, b) ) ,
473
437
}
474
438
}
475
439
}
476
440
477
441
impl < ' tcx > ToTrace < ' tcx > for ty:: FnSig < ' tcx > {
478
- fn to_trace (
479
- cause : & ObligationCause < ' tcx > ,
480
- a_is_expected : bool ,
481
- a : Self ,
482
- b : Self ,
483
- ) -> TypeTrace < ' tcx > {
442
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
484
443
TypeTrace {
485
444
cause : cause. clone ( ) ,
486
445
values : ValuePairs :: PolySigs ( ExpectedFound :: new (
487
- a_is_expected ,
446
+ true ,
488
447
ty:: Binder :: dummy ( a) ,
489
448
ty:: Binder :: dummy ( b) ,
490
449
) ) ,
@@ -493,43 +452,28 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
493
452
}
494
453
495
454
impl < ' tcx > ToTrace < ' tcx > for ty:: PolyFnSig < ' tcx > {
496
- fn to_trace (
497
- cause : & ObligationCause < ' tcx > ,
498
- a_is_expected : bool ,
499
- a : Self ,
500
- b : Self ,
501
- ) -> TypeTrace < ' tcx > {
455
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
502
456
TypeTrace {
503
457
cause : cause. clone ( ) ,
504
- values : ValuePairs :: PolySigs ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
458
+ values : ValuePairs :: PolySigs ( ExpectedFound :: new ( true , a, b) ) ,
505
459
}
506
460
}
507
461
}
508
462
509
463
impl < ' tcx > ToTrace < ' tcx > for ty:: PolyExistentialTraitRef < ' tcx > {
510
- fn to_trace (
511
- cause : & ObligationCause < ' tcx > ,
512
- a_is_expected : bool ,
513
- a : Self ,
514
- b : Self ,
515
- ) -> TypeTrace < ' tcx > {
464
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
516
465
TypeTrace {
517
466
cause : cause. clone ( ) ,
518
- values : ValuePairs :: ExistentialTraitRef ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
467
+ values : ValuePairs :: ExistentialTraitRef ( ExpectedFound :: new ( true , a, b) ) ,
519
468
}
520
469
}
521
470
}
522
471
523
472
impl < ' tcx > ToTrace < ' tcx > for ty:: PolyExistentialProjection < ' tcx > {
524
- fn to_trace (
525
- cause : & ObligationCause < ' tcx > ,
526
- a_is_expected : bool ,
527
- a : Self ,
528
- b : Self ,
529
- ) -> TypeTrace < ' tcx > {
473
+ fn to_trace ( cause : & ObligationCause < ' tcx > , a : Self , b : Self ) -> TypeTrace < ' tcx > {
530
474
TypeTrace {
531
475
cause : cause. clone ( ) ,
532
- values : ValuePairs :: ExistentialProjection ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
476
+ values : ValuePairs :: ExistentialProjection ( ExpectedFound :: new ( true , a, b) ) ,
533
477
}
534
478
}
535
479
}
0 commit comments