Skip to content

Commit b4af5d3

Browse files
committed
Auto merge of rust-lang#121864 - compiler-errors:type-relating-variances, r=<try>
Don't grab variances in `TypeRelating` relation if we're invariant Since `Invariant.xform(var) = Invariant` always, so just copy what the generalizer relation does. Fixes rust-lang#110106
2 parents 6db96de + cb7c9cc commit b4af5d3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

compiler/rustc_infer/src/infer/relate/type_relating.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::infer::{
55
};
66
use crate::traits::{Obligation, PredicateObligations};
77

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+
};
911
use rustc_middle::ty::TyVar;
1012
use rustc_middle::ty::{self, Ty, TyCtxt};
1113
use rustc_span::Span;
@@ -36,6 +38,24 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
3638
self.fields.infcx.tcx
3739
}
3840

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+
3959
fn relate_with_variance<T: Relate<'tcx>>(
4060
&mut self,
4161
variance: ty::Variance,

0 commit comments

Comments
 (0)