@@ -577,20 +577,45 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
577577 a : ty:: Const < ' tcx > ,
578578 b : ty:: Const < ' tcx > ,
579579) -> 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 > > {
583608 let a_ty;
584609 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 ( ) ) ;
588613 } else {
589614 a_ty = tcx. erase_regions ( a. ty ( ) ) ;
590615 b_ty = tcx. erase_regions ( b. ty ( ) ) ;
591616 }
592617 if a_ty != b_ty {
593- relation . tcx ( ) . sess . delay_span_bug (
618+ tcx. sess . delay_span_bug (
594619 DUMMY_SP ,
595620 & format ! ( "cannot relate constants of different types: {} != {}" , a_ty, b_ty) ,
596621 ) ;
@@ -615,7 +640,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
615640 ( ty:: ConstKind :: Unevaluated ( au) , ty:: ConstKind :: Unevaluated ( bu) )
616641 if tcx. features ( ) . generic_const_exprs =>
617642 {
618- tcx. try_unify_abstract_consts ( relation . param_env ( ) . and ( ( au, bu) ) )
643+ tcx. try_unify_abstract_consts ( param_env. and ( ( au, bu) ) )
619644 }
620645
621646 // 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>>(
625650 if au. def == bu. def && au. promoted == bu. promoted =>
626651 {
627652 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 ) ?;
635654 return Ok ( tcx. mk_const ( ty:: ConstS {
636655 kind : ty:: ConstKind :: Unevaluated ( ty:: Unevaluated {
637656 def : au. def ,
@@ -643,7 +662,11 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
643662 }
644663 _ => false ,
645664 } ;
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+ }
647670}
648671
649672impl < ' tcx > Relate < ' tcx > for & ' tcx ty:: List < ty:: Binder < ' tcx , ty:: ExistentialPredicate < ' tcx > > > {
0 commit comments