@@ -99,6 +99,12 @@ pub trait TypeRelation<'tcx>: Sized {
9999 ) -> RelateResult < ' tcx , ty:: Binder < ' tcx , T > >
100100 where
101101 T : Relate < ' tcx > ;
102+
103+ fn constness_args (
104+ & mut self ,
105+ a : ty:: ConstnessArg ,
106+ b : ty:: ConstnessArg ,
107+ ) -> RelateResult < ' tcx , ty:: ConstnessArg > ;
102108}
103109
104110pub trait Relate < ' tcx > : TypeFoldable < ' tcx > + Copy {
@@ -141,7 +147,11 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
141147 b_subst : SubstsRef < ' tcx > ,
142148) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
143149 relation. tcx ( ) . mk_substs ( iter:: zip ( a_subst, b_subst) . map ( |( a, b) | {
144- relation. relate_with_variance ( ty:: Invariant , ty:: VarianceDiagInfo :: default ( ) , a, b)
150+ if let GenericArgKind :: Constness ( _) = a. unpack ( ) && let GenericArgKind :: Constness ( _) = b. unpack ( ) {
151+ relation. relate ( a, b)
152+ } else {
153+ relation. relate_with_variance ( ty:: Invariant , ty:: VarianceDiagInfo :: default ( ) , a, b)
154+ }
145155 } ) )
146156}
147157
@@ -232,11 +242,7 @@ impl<'tcx> Relate<'tcx> for ty::ConstnessArg {
232242 a : ty:: ConstnessArg ,
233243 b : ty:: ConstnessArg ,
234244 ) -> RelateResult < ' tcx , ty:: ConstnessArg > {
235- if a == b {
236- Ok ( a)
237- } else {
238- Err ( TypeError :: ConstnessArgMismatch ( expected_found ( relation, a, b) ) )
239- }
245+ relation. constness_args ( a, b)
240246 }
241247}
242248
@@ -660,6 +666,20 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
660666 if is_match { Ok ( a) } else { Err ( TypeError :: ConstMismatch ( expected_found ( relation, a, b) ) ) }
661667}
662668
669+ pub fn super_relate_constness < ' tcx , R : TypeRelation < ' tcx > > (
670+ relation : & mut R ,
671+ a : ty:: ConstnessArg ,
672+ b : ty:: ConstnessArg ,
673+ ) -> RelateResult < ' tcx , ty:: ConstnessArg > {
674+ match ( a, b) {
675+ ( ty:: ConstnessArg :: Infer , _) | ( _, ty:: ConstnessArg :: Infer ) => {
676+ bug ! ( "var types encountered in super_relate_contness: {a:?} {b:?}" ) ;
677+ }
678+ ( a, b) if a == b => Ok ( a) ,
679+ _ => Err ( TypeError :: ConstnessArgMismatch ( expected_found ( relation, a, b) ) ) ,
680+ }
681+ }
682+
663683impl < ' tcx > Relate < ' tcx > for & ' tcx ty:: List < ty:: Binder < ' tcx , ty:: ExistentialPredicate < ' tcx > > > {
664684 fn relate < R : TypeRelation < ' tcx > > (
665685 relation : & mut R ,
0 commit comments