use abstract consts when unifying ConstKind::Unevaluated
This commit is contained in:
parent
d327fa112b
commit
c3a772f55f
8 changed files with 96 additions and 10 deletions
|
@ -269,7 +269,27 @@ pub(super) fn mir_abstract_const<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn try_unify<'tcx>(tcx: TyCtxt<'tcx>, a: AbstractConst<'tcx>, b: AbstractConst<'tcx>) -> bool {
|
||||
pub(super) fn try_unify_abstract_consts<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
((a, a_substs), (b, b_substs)): (
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||
),
|
||||
) -> bool {
|
||||
if let Some(a) = AbstractConst::new(tcx, a, a_substs) {
|
||||
if let Some(b) = AbstractConst::new(tcx, b, b_substs) {
|
||||
return try_unify(tcx, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub(super) fn try_unify<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
a: AbstractConst<'tcx>,
|
||||
b: AbstractConst<'tcx>,
|
||||
) -> bool {
|
||||
match (a.root(), b.root()) {
|
||||
(Node::Leaf(a_ct), Node::Leaf(b_ct)) => {
|
||||
let a_ct = a_ct.subst(tcx, a.substs);
|
||||
|
|
|
@ -476,6 +476,25 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
|||
|
||||
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
||||
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
|
||||
if self.selcx.tcx().features().const_evaluatable_checked {
|
||||
// FIXME: we probably should only try to unify abstract constants
|
||||
// if the constants depend on generic parameters.
|
||||
//
|
||||
// Let's just see where this breaks :shrug:
|
||||
if let (
|
||||
ty::ConstKind::Unevaluated(a_def, a_substs, None),
|
||||
ty::ConstKind::Unevaluated(b_def, b_substs, None),
|
||||
) = (c1.val, c2.val)
|
||||
{
|
||||
if self
|
||||
.selcx
|
||||
.tcx()
|
||||
.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs)))
|
||||
{
|
||||
return ProcessResult::Changed(vec![]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let stalled_on = &mut pending_obligation.stalled_on;
|
||||
|
||||
|
|
|
@ -566,6 +566,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
ty::WithOptConstParam { did, const_param_did: Some(param_did) },
|
||||
)
|
||||
},
|
||||
try_unify_abstract_consts: const_evaluatable::try_unify_abstract_consts,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue