@@ -60,7 +60,7 @@ pub trait TypeRelation<'tcx>: Sized {
60
60
61
61
let tcx = self . tcx ( ) ;
62
62
let opt_variances = tcx. variances_of ( item_def_id) ;
63
- relate_substs_with_variances ( self , item_def_id, opt_variances, a_subst, b_subst)
63
+ relate_substs_with_variances ( self , item_def_id, opt_variances, a_subst, b_subst, true )
64
64
}
65
65
66
66
/// Switch variance for the purpose of relating `a` and `b`.
@@ -151,13 +151,14 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
151
151
variances : & [ ty:: Variance ] ,
152
152
a_subst : SubstsRef < ' tcx > ,
153
153
b_subst : SubstsRef < ' tcx > ,
154
+ fetch_ty_for_diag : bool ,
154
155
) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
155
156
let tcx = relation. tcx ( ) ;
156
157
157
158
let mut cached_ty = None ;
158
159
let params = iter:: zip ( a_subst, b_subst) . enumerate ( ) . map ( |( i, ( a, b) ) | {
159
160
let variance = variances[ i] ;
160
- let variance_info = if variance == ty:: Invariant {
161
+ let variance_info = if variance == ty:: Invariant && fetch_ty_for_diag {
161
162
let ty =
162
163
* cached_ty. get_or_insert_with ( || tcx. bound_type_of ( ty_def_id) . subst ( tcx, a_subst) ) ;
163
164
ty:: VarianceDiagInfo :: Invariant { ty, param_index : i. try_into ( ) . unwrap ( ) }
@@ -170,26 +171,6 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
170
171
tcx. mk_substs ( params)
171
172
}
172
173
173
- #[ instrument( level = "trace" , skip( relation) , ret) ]
174
- fn relate_opaque_item_substs < ' tcx , R : TypeRelation < ' tcx > > (
175
- relation : & mut R ,
176
- def_id : DefId ,
177
- a_subst : SubstsRef < ' tcx > ,
178
- b_subst : SubstsRef < ' tcx > ,
179
- ) -> RelateResult < ' tcx , SubstsRef < ' tcx > > {
180
- let tcx = relation. tcx ( ) ;
181
- let variances = tcx. variances_of ( def_id) ;
182
- debug ! ( ?variances) ;
183
-
184
- let params = iter:: zip ( a_subst, b_subst) . enumerate ( ) . map ( |( i, ( a, b) ) | {
185
- let variance = variances[ i] ;
186
- let variance_info = ty:: VarianceDiagInfo :: default ( ) ;
187
- relation. relate_with_variance ( variance, variance_info, a, b)
188
- } ) ;
189
-
190
- tcx. mk_substs ( params)
191
- }
192
-
193
174
impl < ' tcx > Relate < ' tcx > for ty:: FnSig < ' tcx > {
194
175
fn relate < R : TypeRelation < ' tcx > > (
195
176
relation : & mut R ,
@@ -581,7 +562,15 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
581
562
( & ty:: Opaque ( a_def_id, a_substs) , & ty:: Opaque ( b_def_id, b_substs) )
582
563
if a_def_id == b_def_id =>
583
564
{
584
- let substs = relate_opaque_item_substs ( relation, a_def_id, a_substs, b_substs) ?;
565
+ let opt_variances = tcx. variances_of ( a_def_id) ;
566
+ let substs = relate_substs_with_variances (
567
+ relation,
568
+ a_def_id,
569
+ opt_variances,
570
+ a_substs,
571
+ b_substs,
572
+ false , // do not fetch `type_of(a_def_id)`, as it will cause a cycle
573
+ ) ?;
585
574
Ok ( tcx. mk_opaque ( a_def_id, substs) )
586
575
}
587
576
0 commit comments