@@ -577,20 +577,45 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
577
577
a : ty:: Const < ' tcx > ,
578
578
b : ty:: Const < ' tcx > ,
579
579
) -> RelateResult < ' tcx , ty:: Const < ' tcx > > {
580
- debug ! ( "{}.super_relate_consts(a = {:?}, b = {:?})" , relation. tag( ) , a, b) ;
581
- let tcx = relation. tcx ( ) ;
582
-
580
+ inner_super_relate_consts (
581
+ relation. tcx ( ) ,
582
+ relation. param_env ( ) ,
583
+ relation. a_is_expected ( ) ,
584
+ & mut |a_substs, b_substs| {
585
+ relation. relate_with_variance (
586
+ ty:: Variance :: Invariant ,
587
+ ty:: VarianceDiagInfo :: default ( ) ,
588
+ a_substs,
589
+ b_substs,
590
+ )
591
+ } ,
592
+ a,
593
+ b,
594
+ )
595
+ }
596
+
597
+ fn inner_super_relate_consts < ' tcx > (
598
+ tcx : TyCtxt < ' tcx > ,
599
+ param_env : ty:: ParamEnv < ' tcx > ,
600
+ a_is_expected : bool ,
601
+ recurse_unevaluated : & mut dyn FnMut (
602
+ SubstsRef < ' tcx > ,
603
+ SubstsRef < ' tcx > ,
604
+ ) -> RelateResult < ' tcx , SubstsRef < ' tcx > > ,
605
+ a : ty:: Const < ' tcx > ,
606
+ b : ty:: Const < ' tcx > ,
607
+ ) -> RelateResult < ' tcx , ty:: Const < ' tcx > > {
583
608
let a_ty;
584
609
let b_ty;
585
- if relation . tcx ( ) . features ( ) . adt_const_params {
586
- a_ty = tcx. normalize_erasing_regions ( relation . param_env ( ) , a. ty ( ) ) ;
587
- b_ty = tcx. normalize_erasing_regions ( relation . param_env ( ) , b. ty ( ) ) ;
610
+ if tcx. features ( ) . adt_const_params {
611
+ a_ty = tcx. normalize_erasing_regions ( param_env, a. ty ( ) ) ;
612
+ b_ty = tcx. normalize_erasing_regions ( param_env, b. ty ( ) ) ;
588
613
} else {
589
614
a_ty = tcx. erase_regions ( a. ty ( ) ) ;
590
615
b_ty = tcx. erase_regions ( b. ty ( ) ) ;
591
616
}
592
617
if a_ty != b_ty {
593
- relation . tcx ( ) . sess . delay_span_bug (
618
+ tcx. sess . delay_span_bug (
594
619
DUMMY_SP ,
595
620
& format ! ( "cannot relate constants of different types: {} != {}" , a_ty, b_ty) ,
596
621
) ;
@@ -615,7 +640,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
615
640
( ty:: ConstKind :: Unevaluated ( au) , ty:: ConstKind :: Unevaluated ( bu) )
616
641
if tcx. features ( ) . generic_const_exprs =>
617
642
{
618
- tcx. try_unify_abstract_consts ( relation . param_env ( ) . and ( ( au, bu) ) )
643
+ tcx. try_unify_abstract_consts ( param_env. and ( ( au, bu) ) )
619
644
}
620
645
621
646
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
@@ -625,13 +650,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
625
650
if au. def == bu. def && au. promoted == bu. promoted =>
626
651
{
627
652
assert_eq ! ( au. promoted, ( ) ) ;
628
-
629
- let substs = relation. relate_with_variance (
630
- ty:: Variance :: Invariant ,
631
- ty:: VarianceDiagInfo :: default ( ) ,
632
- au. substs ,
633
- bu. substs ,
634
- ) ?;
653
+ let substs = recurse_unevaluated ( au. substs , bu. substs ) ?;
635
654
return Ok ( tcx. mk_const ( ty:: ConstS {
636
655
kind : ty:: ConstKind :: Unevaluated ( ty:: Unevaluated {
637
656
def : au. def ,
@@ -643,7 +662,11 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
643
662
}
644
663
_ => false ,
645
664
} ;
646
- if is_match { Ok ( a) } else { Err ( TypeError :: ConstMismatch ( expected_found ( relation, a, b) ) ) }
665
+ if is_match {
666
+ Ok ( a)
667
+ } else {
668
+ Err ( TypeError :: ConstMismatch ( ExpectedFound :: new ( a_is_expected, a, b) ) )
669
+ }
647
670
}
648
671
649
672
impl < ' tcx > Relate < ' tcx > for & ' tcx ty:: List < ty:: Binder < ' tcx , ty:: ExistentialPredicate < ' tcx > > > {
0 commit comments