Skip to content

Commit

Permalink
Fix generalizer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 22, 2024
1 parent f5631bf commit 8ba73e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
16 changes: 3 additions & 13 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,10 @@ impl<'tcx> InferCtxt<'tcx> {
} else {
// HACK: make sure that we `a_is_expected` continues to be
// correct when relating the generalized type with the source.
if target_is_expected == relation.a_is_expected() {
relation.relate_with_variance(
ambient_variance,
ty::VarianceDiagInfo::default(),
generalized_ty,
source_ty,
)?;
if target_is_expected {
relation.relate(generalized_ty, source_ty)?;
} else {
relation.relate_with_variance(
ambient_variance.xform(ty::Contravariant),
ty::VarianceDiagInfo::default(),
source_ty,
generalized_ty,
)?;
relation.relate(source_ty, generalized_ty)?;
}
}

Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_infer/src/infer/relate/type_relating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,12 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
}

(&ty::Infer(TyVar(a_vid)), _) => {
infcx.instantiate_ty_var(
self,
self.a_is_expected,
a_vid,
self.ambient_variance,
b,
)?;
infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?;
}
(_, &ty::Infer(TyVar(b_vid))) => {
infcx.instantiate_ty_var(
self,
!self.a_is_expected,
false,
b_vid,
self.ambient_variance.xform(ty::Contravariant),
a,
Expand Down

0 comments on commit 8ba73e7

Please sign in to comment.