From 8ba73e71f04ffca662cc0ac9c80f86fb316bdf39 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 22 Feb 2024 20:51:07 +0000 Subject: [PATCH] Fix generalizer bug --- .../rustc_infer/src/infer/relate/generalize.rs | 16 +++------------- .../src/infer/relate/type_relating.rs | 10 ++-------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index 42e94a7dd9639..76472975cd0af 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -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)?; } } diff --git a/compiler/rustc_infer/src/infer/relate/type_relating.rs b/compiler/rustc_infer/src/infer/relate/type_relating.rs index 94e7c4047683b..eae07ba41338a 100644 --- a/compiler/rustc_infer/src/infer/relate/type_relating.rs +++ b/compiler/rustc_infer/src/infer/relate/type_relating.rs @@ -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,