@@ -92,12 +92,7 @@ impl<'tcx> InferCtxt<'tcx> {
9292}
9393
9494pub 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 > ;
10196}
10297
10398impl < ' a , ' tcx > At < ' a , ' tcx > {
@@ -116,7 +111,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
116111{
117112let mut fields = CombineFields :: new (
118113self . infcx ,
119- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
114+ ToTrace :: to_trace ( self . cause , expected, actual) ,
120115self . param_env ,
121116 define_opaque_types,
122117) ;
@@ -136,7 +131,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
136131{
137132let mut fields = CombineFields :: new (
138133self . infcx ,
139- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
134+ ToTrace :: to_trace ( self . cause , expected, actual) ,
140135self . param_env ,
141136 define_opaque_types,
142137) ;
@@ -154,12 +149,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
154149where
155150T : ToTrace < ' tcx > ,
156151{
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 (
161153 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) ;
163172 fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
164173Ok ( InferOk {
165174value : ( ) ,
@@ -192,7 +201,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
192201assert ! ( self . infcx. next_trait_solver( ) ) ;
193202let mut fields = CombineFields :: new (
194203self . infcx ,
195- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
204+ ToTrace :: to_trace ( self . cause , expected, actual) ,
196205self . param_env ,
197206DefineOpaqueTypes :: Yes ,
198207) ;
@@ -284,7 +293,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
284293{
285294let mut fields = CombineFields :: new (
286295self . infcx ,
287- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
296+ ToTrace :: to_trace ( self . cause , expected, actual) ,
288297self . param_env ,
289298 define_opaque_types,
290299) ;
@@ -306,7 +315,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
306315{
307316let mut fields = CombineFields :: new (
308317self . infcx ,
309- ToTrace :: to_trace ( self . cause , true , expected, actual) ,
318+ ToTrace :: to_trace ( self . cause , expected, actual) ,
310319self . param_env ,
311320 define_opaque_types,
312321) ;
@@ -316,18 +325,13 @@ impl<'a, 'tcx> At<'a, 'tcx> {
316325}
317326
318327impl < ' 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 > {
325329match ( a, b) {
326330( 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)
328332}
329333( 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)
331335}
332336( ImplSubject :: Trait ( _) , ImplSubject :: Inherent ( _) )
333337 | ( ImplSubject :: Inherent ( _) , ImplSubject :: Trait ( _) ) => {
@@ -338,65 +342,45 @@ impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
338342}
339343
340344impl < ' 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 > {
347346TypeTrace {
348347cause : 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 ( ) ) ) ,
350349}
351350}
352351}
353352
354353impl < ' 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 > {
361355TypeTrace {
362356cause : cause. clone ( ) ,
363- values : ValuePairs :: Regions ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
357+ values : ValuePairs :: Regions ( ExpectedFound :: new ( true , a, b) ) ,
364358}
365359}
366360}
367361
368362impl < ' 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 > {
375364TypeTrace {
376365cause : 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 ( ) ) ) ,
378367}
379368}
380369}
381370
382371impl < ' 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 > {
389373TypeTrace {
390374cause : cause. clone ( ) ,
391375values : match ( a. unpack ( ) , b. unpack ( ) ) {
392376( GenericArgKind :: Lifetime ( a) , GenericArgKind :: Lifetime ( b) ) => {
393- ValuePairs :: Regions ( ExpectedFound :: new ( a_is_expected , a, b) )
377+ ValuePairs :: Regions ( ExpectedFound :: new ( true , a, b) )
394378}
395379( 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 ( ) ) )
397381}
398382( 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 ( ) ) )
400384}
401385
402386(
@@ -419,72 +403,47 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
419403}
420404
421405impl < ' 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 > {
428407TypeTrace {
429408cause : cause. clone ( ) ,
430- values : ValuePairs :: Terms ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
409+ values : ValuePairs :: Terms ( ExpectedFound :: new ( true , a, b) ) ,
431410}
432411}
433412}
434413
435414impl < ' 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 > {
442416TypeTrace {
443417cause : cause. clone ( ) ,
444- values : ValuePairs :: TraitRefs ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
418+ values : ValuePairs :: TraitRefs ( ExpectedFound :: new ( true , a, b) ) ,
445419}
446420}
447421}
448422
449423impl < ' 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 > {
456425TypeTrace {
457426cause : 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 ( ) ) ) ,
459428}
460429}
461430}
462431
463432impl < ' 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 > {
470434TypeTrace {
471435cause : cause. clone ( ) ,
472- values : ValuePairs :: Aliases ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
436+ values : ValuePairs :: Aliases ( ExpectedFound :: new ( true , a, b) ) ,
473437}
474438}
475439}
476440
477441impl < ' 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 > {
484443TypeTrace {
485444cause : cause. clone ( ) ,
486445values : ValuePairs :: PolySigs ( ExpectedFound :: new (
487- a_is_expected ,
446+ true ,
488447 ty:: Binder :: dummy ( a) ,
489448 ty:: Binder :: dummy ( b) ,
490449) ) ,
@@ -493,43 +452,28 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
493452}
494453
495454impl < ' 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 > {
502456TypeTrace {
503457cause : cause. clone ( ) ,
504- values : ValuePairs :: PolySigs ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
458+ values : ValuePairs :: PolySigs ( ExpectedFound :: new ( true , a, b) ) ,
505459}
506460}
507461}
508462
509463impl < ' 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 > {
516465TypeTrace {
517466cause : cause. clone ( ) ,
518- values : ValuePairs :: ExistentialTraitRef ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
467+ values : ValuePairs :: ExistentialTraitRef ( ExpectedFound :: new ( true , a, b) ) ,
519468}
520469}
521470}
522471
523472impl < ' 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 > {
530474TypeTrace {
531475cause : cause. clone ( ) ,
532- values : ValuePairs :: ExistentialProjection ( ExpectedFound :: new ( a_is_expected , a, b) ) ,
476+ values : ValuePairs :: ExistentialProjection ( ExpectedFound :: new ( true , a, b) ) ,
533477}
534478}
535479}
0 commit comments