combine: stop eagerly evaluating consts
This commit is contained in:
parent
aef11409b4
commit
42150fb8a1
14 changed files with 106 additions and 27 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -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)))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue