@@ -61,7 +61,7 @@ pub trait TypeRelation<'tcx>: Sized {
61
61
62
62
let tcx = self . tcx ( ) ;
63
63
let opt_variances = tcx. variances_of ( item_def_id) ;
64
- relate_substs ( self , Some ( ( item_def_id, opt_variances) ) , a_subst, b_subst)
64
+ relate_substs_with_variances ( self , item_def_id, opt_variances, a_subst, b_subst)
65
65
}
66
66
67
67
/// Switch variance for the purpose of relating `a` and `b`.
@@ -135,29 +135,34 @@ pub fn relate_type_and_mut<'tcx, R: TypeRelation<'tcx>>(
135
135
}
136
136
}
137
137
138
+ #[ inline]
138
139
pub fn relate_substs < ' tcx , R : TypeRelation < ' tcx > > (
139
140
relation : & mut R ,
140
- variances : Option < ( DefId , & [ ty:: Variance ] ) > ,
141
+ a_subst : SubstsRef < ' tcx > ,
142
+ b_subst : SubstsRef < ' tcx > ,
143
+ ) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
144
+ relation. tcx ( ) . mk_substs ( iter:: zip ( a_subst, b_subst) . map ( |( a, b) | {
145
+ relation. relate_with_variance ( ty:: Invariant , ty:: VarianceDiagInfo :: default ( ) , a, b)
146
+ } ) )
147
+ }
148
+
149
+ pub fn relate_substs_with_variances < ' tcx , R : TypeRelation < ' tcx > > (
150
+ relation : & mut R ,
151
+ ty_def_id : DefId ,
152
+ variances : & [ ty:: Variance ] ,
141
153
a_subst : SubstsRef < ' tcx > ,
142
154
b_subst : SubstsRef < ' tcx > ,
143
155
) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
144
156
let tcx = relation. tcx ( ) ;
145
- let mut cached_ty = None ;
146
157
158
+ let mut cached_ty = None ;
147
159
let params = iter:: zip ( a_subst, b_subst) . enumerate ( ) . map ( |( i, ( a, b) ) | {
148
- let ( variance, variance_info) = match variances {
149
- Some ( ( ty_def_id, variances) ) => {
150
- let variance = variances[ i] ;
151
- let variance_info = if variance == ty:: Invariant {
152
- let ty = * cached_ty
153
- . get_or_insert_with ( || tcx. type_of ( ty_def_id) . subst ( tcx, a_subst) ) ;
154
- ty:: VarianceDiagInfo :: Invariant { ty, param_index : i. try_into ( ) . unwrap ( ) }
155
- } else {
156
- ty:: VarianceDiagInfo :: default ( )
157
- } ;
158
- ( variance, variance_info)
159
- }
160
- None => ( ty:: Invariant , ty:: VarianceDiagInfo :: default ( ) ) ,
160
+ let variance = variances[ i] ;
161
+ let variance_info = if variance == ty:: Invariant {
162
+ let ty = * cached_ty. get_or_insert_with ( || tcx. type_of ( ty_def_id) . subst ( tcx, a_subst) ) ;
163
+ ty:: VarianceDiagInfo :: Invariant { ty, param_index : i. try_into ( ) . unwrap ( ) }
164
+ } else {
165
+ ty:: VarianceDiagInfo :: default ( )
161
166
} ;
162
167
relation. relate_with_variance ( variance, variance_info, a, b)
163
168
} ) ;
@@ -318,7 +323,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
318
323
if a. def_id != b. def_id {
319
324
Err ( TypeError :: Traits ( expected_found ( relation, a. def_id , b. def_id ) ) )
320
325
} else {
321
- let substs = relate_substs ( relation, None , a. substs , b. substs ) ?;
326
+ let substs = relate_substs ( relation, a. substs , b. substs ) ?;
322
327
Ok ( ty:: TraitRef { def_id : a. def_id , substs } )
323
328
}
324
329
}
@@ -334,7 +339,7 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
334
339
if a. def_id != b. def_id {
335
340
Err ( TypeError :: Traits ( expected_found ( relation, a. def_id , b. def_id ) ) )
336
341
} else {
337
- let substs = relate_substs ( relation, None , a. substs , b. substs ) ?;
342
+ let substs = relate_substs ( relation, a. substs , b. substs ) ?;
338
343
Ok ( ty:: ExistentialTraitRef { def_id : a. def_id , substs } )
339
344
}
340
345
}
@@ -554,7 +559,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
554
559
( & ty:: Opaque ( a_def_id, a_substs) , & ty:: Opaque ( b_def_id, b_substs) )
555
560
if a_def_id == b_def_id =>
556
561
{
557
- let substs = relate_substs ( relation, None , a_substs, b_substs) ?;
562
+ let substs = relate_substs ( relation, a_substs, b_substs) ?;
558
563
Ok ( tcx. mk_opaque ( a_def_id, substs) )
559
564
}
560
565
@@ -742,7 +747,7 @@ impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
742
747
a : ty:: ClosureSubsts < ' tcx > ,
743
748
b : ty:: ClosureSubsts < ' tcx > ,
744
749
) -> RelateResult < ' tcx , ty:: ClosureSubsts < ' tcx > > {
745
- let substs = relate_substs ( relation, None , a. substs , b. substs ) ?;
750
+ let substs = relate_substs ( relation, a. substs , b. substs ) ?;
746
751
Ok ( ty:: ClosureSubsts { substs } )
747
752
}
748
753
}
@@ -753,7 +758,7 @@ impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> {
753
758
a : ty:: GeneratorSubsts < ' tcx > ,
754
759
b : ty:: GeneratorSubsts < ' tcx > ,
755
760
) -> RelateResult < ' tcx , ty:: GeneratorSubsts < ' tcx > > {
756
- let substs = relate_substs ( relation, None , a. substs , b. substs ) ?;
761
+ let substs = relate_substs ( relation, a. substs , b. substs ) ?;
757
762
Ok ( ty:: GeneratorSubsts { substs } )
758
763
}
759
764
}
@@ -764,7 +769,7 @@ impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> {
764
769
a : SubstsRef < ' tcx > ,
765
770
b : SubstsRef < ' tcx > ,
766
771
) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
767
- relate_substs ( relation, None , a, b)
772
+ relate_substs ( relation, a, b)
768
773
}
769
774
}
770
775
0 commit comments