@@ -5,7 +5,9 @@ use crate::infer::{
5
5
} ;
6
6
use crate :: traits:: { Obligation , PredicateObligations } ;
7
7
8
- use rustc_middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
8
+ use rustc_middle:: ty:: relate:: {
9
+ relate_args_invariantly, relate_args_with_variances, Relate , RelateResult , TypeRelation ,
10
+ } ;
9
11
use rustc_middle:: ty:: TyVar ;
10
12
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
11
13
use rustc_span:: Span ;
@@ -36,6 +38,24 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
36
38
self . fields . infcx . tcx
37
39
}
38
40
41
+ fn relate_item_args (
42
+ & mut self ,
43
+ item_def_id : rustc_hir:: def_id:: DefId ,
44
+ a_arg : ty:: GenericArgsRef < ' tcx > ,
45
+ b_arg : ty:: GenericArgsRef < ' tcx > ,
46
+ ) -> RelateResult < ' tcx , ty:: GenericArgsRef < ' tcx > > {
47
+ if self . ambient_variance == ty:: Variance :: Invariant {
48
+ // Avoid fetching the variance if we are in an invariant
49
+ // context; no need, and it can induce dependency cycles
50
+ // (e.g., #41849).
51
+ relate_args_invariantly ( self , a_arg, b_arg)
52
+ } else {
53
+ let tcx = self . tcx ( ) ;
54
+ let opt_variances = tcx. variances_of ( item_def_id) ;
55
+ relate_args_with_variances ( self , item_def_id, opt_variances, a_arg, b_arg, false )
56
+ }
57
+ }
58
+
39
59
fn relate_with_variance < T : Relate < ' tcx > > (
40
60
& mut self ,
41
61
variance : ty:: Variance ,
0 commit comments