From 8d92e49085e06bfd0d830a79032d3022da2c57bc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Jul 2022 05:55:25 +0000 Subject: [PATCH] Register opaque types even when equated with infer variables --- compiler/rustc_infer/src/infer/equate.rs | 26 +++++++++---------- .../rustc_infer/src/infer/opaque_types.rs | 11 +------- compiler/rustc_infer/src/infer/sub.rs | 2 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index 3b1798ca73746..9088822fa91e5 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -80,20 +80,8 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b); match (a.kind(), b.kind()) { - (&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => { - infcx.inner.borrow_mut().type_variables().equate(a_id, b_id); - } - - (&ty::Infer(TyVar(a_id)), _) => { - self.fields.instantiate(b, RelationDir::EqTo, a_id, self.a_is_expected)?; - } - - (_, &ty::Infer(TyVar(b_id))) => { - self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?; - } - (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { - self.fields.infcx.super_combine_tys(self, a, b)?; + self.infcx.super_combine_tys(self, a, b) } (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) if self.fields.define_opaque_types && did.is_local() => @@ -111,6 +99,18 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { ); } + (&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => { + infcx.inner.borrow_mut().type_variables().equate(a_id, b_id); + } + + (&ty::Infer(TyVar(a_id)), _) => { + self.fields.instantiate(b, RelationDir::EqTo, a_id, self.a_is_expected)?; + } + + (_, &ty::Infer(TyVar(b_id))) => { + self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?; + } + _ => { self.fields.infcx.super_combine_tys(self, a, b)?; } diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 7b0ff9552a3a4..7637af737412c 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -184,16 +184,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } else if let Some(res) = process(b, a) { res } else { - // Rerun equality check, but this time error out due to - // different types. - match self.at(cause, param_env).define_opaque_types(false).eq(a, b) { - Ok(_) => span_bug!( - cause.span, - "opaque types are never equal to anything but themselves: {:#?}", - (a.kind(), b.kind()) - ), - Err(e) => Err(e), - } + self.at(cause, param_env).define_opaque_types(false).eq(a, b) } } diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index b27571275b733..744de904efda4 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -90,7 +90,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { // Shouldn't have any LBR here, so we can safely put // this under a binder below without fear of accidental // capture. - assert!(!a.has_escaping_bound_vars()); + assert!(!a.has_escaping_bound_vars()); assert!(!b.has_escaping_bound_vars()); // can't make progress on `A <: B` if both A and B are