diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-03-27 20:37:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-27 20:37:04 +0100 |
| commit | 520c9a25dfc78ca1e1d198e55bb4bcb844b0791e (patch) | |
| tree | e007583c06fd7a26f8cb73a0b197993c3e289dfa /compiler | |
| parent | afaf33dcafe9c7068b63eb997df221aa08db7c29 (diff) | |
| parent | e461dddf5828d729b872e27d1a7a7335437ce413 (diff) | |
| download | rust-520c9a25dfc78ca1e1d198e55bb4bcb844b0791e.tar.gz rust-520c9a25dfc78ca1e1d198e55bb4bcb844b0791e.zip | |
Rollup merge of #81351 - lcnr:big-money-big-prices, r=oli-obk
combine: stop eagerly evaluating consts `super_relate_consts` eagerly evaluates constants which doesn't seem too great. I now also finally understand why all of the unused substs test passed. The reason being that we just evaluated the constants in `super_relate_consts` :laughing: While this change isn't strictly necessary as evaluating consts here doesn't hurt, it still feels a lot cleaner to do it this way r? `@oli-obk` `@nikomatsakis`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 17 |
2 files changed, 24 insertions, 21 deletions
diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 5e11932eafc..ffe947d209d 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -543,10 +543,6 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { true } - fn visit_ct_substs(&self) -> bool { - true - } - fn binders<T>( &mut self, a: ty::Binder<T>, @@ -737,6 +733,16 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { } } } + ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) + if self.tcx().lazy_normalization() => + { + assert_eq!(promoted, None); + let substs = self.relate_with_variance(ty::Variance::Invariant, substs, substs)?; + Ok(self.tcx().mk_const(ty::Const { + ty: c.ty, + val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }), + })) + } _ => relate::super_relate_consts(self, c, c), } } @@ -822,10 +828,6 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { true } - fn visit_ct_substs(&self) -> bool { - true - } - fn relate_with_variance<T: Relate<'tcx>>( &mut self, _variance: ty::Variance, @@ -959,6 +961,16 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { } } } + ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) + if self.tcx().lazy_normalization() => + { + assert_eq!(promoted, None); + let substs = self.relate_with_variance(ty::Variance::Invariant, substs, substs)?; + Ok(self.tcx().mk_const(ty::Const { + ty: c.ty, + val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }), + })) + } _ => relate::super_relate_consts(self, c, c), } } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c936c30f456..bc979b885b4 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -33,15 +33,6 @@ pub trait TypeRelation<'tcx>: Sized { /// relation. Just affects error messages. fn a_is_expected(&self) -> bool; - /// Whether we should look into the substs of unevaluated constants - /// even if `feature(const_evaluatable_checked)` is active. - /// - /// This is needed in `combine` to prevent accidentially creating - /// infinite types as we abuse `TypeRelation` to walk a type there. - fn visit_ct_substs(&self) -> bool { - false - } - fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R where F: FnOnce(&mut Self) -> R, @@ -432,9 +423,9 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>( let sz_a = sz_a.try_eval_usize(tcx, relation.param_env()); let sz_b = sz_b.try_eval_usize(tcx, relation.param_env()); match (sz_a, sz_b) { - (Some(sz_a_val), Some(sz_b_val)) => Err(TypeError::FixedArraySize( - expected_found(relation, sz_a_val, sz_b_val), - )), + (Some(sz_a_val), Some(sz_b_val)) if sz_a_val != sz_b_val => Err( + TypeError::FixedArraySize(expected_found(relation, sz_a_val, sz_b_val)), + ), _ => Err(err), } } @@ -532,7 +523,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>( } (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) - if tcx.features().const_evaluatable_checked && !relation.visit_ct_substs() => + if tcx.features().const_evaluatable_checked => { tcx.try_unify_abstract_consts(((au.def, au.substs), (bu.def, bu.substs))) } |
