diff options
| -rw-r--r-- | src/librustc_infer/infer/combine.rs | 17 | ||||
| -rw-r--r-- | src/librustc_infer/infer/equate.rs | 22 | ||||
| -rw-r--r-- | src/librustc_infer/infer/glb.rs | 19 | ||||
| -rw-r--r-- | src/librustc_infer/infer/lub.rs | 19 | ||||
| -rw-r--r-- | src/librustc_infer/infer/nll_relate/mod.rs | 18 | ||||
| -rw-r--r-- | src/librustc_infer/infer/sub.rs | 19 |
6 files changed, 59 insertions, 55 deletions
diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index b995ff989e9..4d7461aa94e 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -126,7 +126,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> where - R: TypeRelation<'tcx>, + R: ConstEquateRelation<'tcx>, { debug!("{}.consts({:?}, {:?})", relation.tag(), a, b); if a == b { @@ -164,6 +164,14 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { (_, ty::ConstKind::Infer(InferConst::Var(vid))) => { return self.unify_const_variable(!a_is_expected, vid, a); } + (ty::ConstKind::Unevaluated(..), _) => { + relation.const_equate_obligation(a, b); + return Ok(b); + } + (_, ty::ConstKind::Unevaluated(..)) => { + relation.const_equate_obligation(a, b); + return Ok(a); + } _ => {} } @@ -656,6 +664,13 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { } } +pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> { + /// Register am obligation that both constants must be equal to each other. + /// + /// If they aren't equal then the relation doesn't hold. + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>); +} + pub trait RelateResultCompare<'tcx, T> { fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T> where diff --git a/src/librustc_infer/infer/equate.rs b/src/librustc_infer/infer/equate.rs index eebcc0ff12a..627580b0474 100644 --- a/src/librustc_infer/infer/equate.rs +++ b/src/librustc_infer/infer/equate.rs @@ -1,10 +1,10 @@ -use super::combine::{CombineFields, RelationDir}; +use super::combine::{CombineFields, RelationDir, ConstEquateRelation}; use super::Subtype; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::TyVar; -use rustc_middle::ty::{self, ConstKind, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_hir::def_id::DefId; @@ -119,17 +119,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> { a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> { - match (a.val, b.val) { - (ConstKind::Unevaluated(..), _) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(b) - } - (_, ConstKind::Unevaluated(..)) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(a) - } - _ => self.fields.infcx.super_combine_consts(self, a, b), - } + self.fields.infcx.super_combine_consts(self, a, b) } fn binders<T>( @@ -150,3 +140,9 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> { } } } + +impl<'tcx> ConstEquateRelation<'tcx> for Equate<'_, '_, 'tcx> { + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) { + self.fields.add_const_equate_obligation(self.a_is_expected, a, b); + } +} diff --git a/src/librustc_infer/infer/glb.rs b/src/librustc_infer/infer/glb.rs index 583e80efc7c..ec219a95b94 100644 --- a/src/librustc_infer/infer/glb.rs +++ b/src/librustc_infer/infer/glb.rs @@ -3,6 +3,7 @@ use super::lattice::{self, LatticeDir}; use super::InferCtxt; use super::Subtype; +use crate::infer::combine::ConstEquateRelation; use crate::traits::ObligationCause; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -79,17 +80,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> { a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> { - match (a.val, b.val) { - (ty::ConstKind::Unevaluated(..), _) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(b) - } - (_, ty::ConstKind::Unevaluated(..)) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(a) - } - _ => self.fields.infcx.super_combine_consts(self, a, b), - } + self.fields.infcx.super_combine_consts(self, a, b) } fn binders<T>( @@ -126,3 +117,9 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx, Ok(()) } } + +impl<'tcx> ConstEquateRelation<'tcx> for Glb<'_, '_, 'tcx> { + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) { + self.fields.add_const_equate_obligation(self.a_is_expected, a, b); + } +} diff --git a/src/librustc_infer/infer/lub.rs b/src/librustc_infer/infer/lub.rs index e613bd5dc7a..a0453db2cb4 100644 --- a/src/librustc_infer/infer/lub.rs +++ b/src/librustc_infer/infer/lub.rs @@ -3,6 +3,7 @@ use super::lattice::{self, LatticeDir}; use super::InferCtxt; use super::Subtype; +use crate::infer::combine::ConstEquateRelation; use crate::traits::ObligationCause; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -79,17 +80,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> { a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> { - match (a.val, b.val) { - (ty::ConstKind::Unevaluated(..), _) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(b) - } - (_, ty::ConstKind::Unevaluated(..)) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(a) - } - _ => self.fields.infcx.super_combine_consts(self, a, b), - } + self.fields.infcx.super_combine_consts(self, a, b) } fn binders<T>( @@ -110,6 +101,12 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> { } } +impl<'tcx> ConstEquateRelation<'tcx> for Lub<'_, '_, 'tcx> { + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) { + self.fields.add_const_equate_obligation(self.a_is_expected, a, b); + } +} + impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx, 'tcx> { fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'tcx> { self.fields.infcx diff --git a/src/librustc_infer/infer/nll_relate/mod.rs b/src/librustc_infer/infer/nll_relate/mod.rs index 32f11abdc97..709aa6b1bb7 100644 --- a/src/librustc_infer/infer/nll_relate/mod.rs +++ b/src/librustc_infer/infer/nll_relate/mod.rs @@ -21,6 +21,7 @@ //! thing we relate in chalk are basically domain goals and their //! constituents) +use crate::infer::combine::ConstEquateRelation; use crate::infer::InferCtxt; use crate::infer::{ConstVarValue, ConstVariableValue}; use rustc_data_structures::fx::FxHashMap; @@ -595,14 +596,6 @@ where } match (a.val, b.val) { - (ty::ConstKind::Unevaluated(..), _) => { - self.delegate.const_equate(a, b); - Ok(b) - } - (_, ty::ConstKind::Unevaluated(..)) => { - self.delegate.const_equate(a, b); - Ok(a) - } (_, ty::ConstKind::Infer(InferConst::Var(_))) if D::forbid_inference_vars() => { // Forbid inference variables in the RHS. bug!("unexpected inference var {:?}", b) @@ -725,6 +718,15 @@ where } } +impl<'tcx, D> ConstEquateRelation<'tcx> for TypeRelating<'_, 'tcx, D> +where + D: TypeRelatingDelegate<'tcx>, +{ + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) { + self.delegate.const_equate(a, b); + } +} + /// When we encounter a binder like `for<..> fn(..)`, we actually have /// to walk the `fn` value to find all the values bound by the `for` /// (these are not explicitly present in the ty representation right diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 91b43dd082f..1ec67ef2efa 100644 --- a/src/librustc_infer/infer/sub.rs +++ b/src/librustc_infer/infer/sub.rs @@ -1,6 +1,7 @@ use super::combine::{CombineFields, RelationDir}; use super::SubregionOrigin; +use crate::infer::combine::ConstEquateRelation; use crate::traits::Obligation; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation}; @@ -155,17 +156,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> { - match (a.val, b.val) { - (ty::ConstKind::Unevaluated(..), _) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(b) - } - (_, ty::ConstKind::Unevaluated(..)) => { - self.fields.add_const_equate_obligation(self.a_is_expected, a, b); - Ok(a) - } - _ => self.fields.infcx.super_combine_consts(self, a, b), - } + self.fields.infcx.super_combine_consts(self, a, b) } fn binders<T>( @@ -179,3 +170,9 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { self.fields.higher_ranked_sub(a, b, self.a_is_expected) } } + +impl<'tcx> ConstEquateRelation<'tcx> for Sub<'_, '_, 'tcx> { + fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) { + self.fields.add_const_equate_obligation(self.a_is_expected, a, b); + } +} |
