Skip to content

Commit 8ba73e7

Browse files
Fix generalizer bug
1 parent f5631bf commit 8ba73e7

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

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

+3-13
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,10 @@ impl<'tcx> InferCtxt<'tcx> {
108108
} else {
109109
// HACK: make sure that we `a_is_expected` continues to be
110110
// correct when relating the generalized type with the source.
111-
if target_is_expected == relation.a_is_expected() {
112-
relation.relate_with_variance(
113-
ambient_variance,
114-
ty::VarianceDiagInfo::default(),
115-
generalized_ty,
116-
source_ty,
117-
)?;
111+
if target_is_expected {
112+
relation.relate(generalized_ty, source_ty)?;
118113
} else {
119-
relation.relate_with_variance(
120-
ambient_variance.xform(ty::Contravariant),
121-
ty::VarianceDiagInfo::default(),
122-
source_ty,
123-
generalized_ty,
124-
)?;
114+
relation.relate(source_ty, generalized_ty)?;
125115
}
126116
}
127117

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,12 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
125125
}
126126

127127
(&ty::Infer(TyVar(a_vid)), _) => {
128-
infcx.instantiate_ty_var(
129-
self,
130-
self.a_is_expected,
131-
a_vid,
132-
self.ambient_variance,
133-
b,
134-
)?;
128+
infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?;
135129
}
136130
(_, &ty::Infer(TyVar(b_vid))) => {
137131
infcx.instantiate_ty_var(
138132
self,
139-
!self.a_is_expected,
133+
false,
140134
b_vid,
141135
self.ambient_variance.xform(ty::Contravariant),
142136
a,

0 commit comments

Comments
 (0)