@@ -99,6 +99,12 @@ pub trait TypeRelation<'tcx>: Sized {
99
99
) -> RelateResult < ' tcx , ty:: Binder < ' tcx , T > >
100
100
where
101
101
T : Relate < ' tcx > ;
102
+
103
+ fn constness_args (
104
+ & mut self ,
105
+ a : ty:: ConstnessArg ,
106
+ b : ty:: ConstnessArg ,
107
+ ) -> RelateResult < ' tcx , ty:: ConstnessArg > ;
102
108
}
103
109
104
110
pub trait Relate < ' tcx > : TypeFoldable < ' tcx > + Copy {
@@ -141,7 +147,11 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
141
147
b_subst : SubstsRef < ' tcx > ,
142
148
) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
143
149
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
+ }
145
155
} ) )
146
156
}
147
157
@@ -232,11 +242,7 @@ impl<'tcx> Relate<'tcx> for ty::ConstnessArg {
232
242
a : ty:: ConstnessArg ,
233
243
b : ty:: ConstnessArg ,
234
244
) -> 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)
240
246
}
241
247
}
242
248
@@ -660,6 +666,20 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
660
666
if is_match { Ok ( a) } else { Err ( TypeError :: ConstMismatch ( expected_found ( relation, a, b) ) ) }
661
667
}
662
668
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
+
663
683
impl < ' tcx > Relate < ' tcx > for & ' tcx ty:: List < ty:: Binder < ' tcx , ty:: ExistentialPredicate < ' tcx > > > {
664
684
fn relate < R : TypeRelation < ' tcx > > (
665
685
relation : & mut R ,
0 commit comments