also handle it in evaluate
This commit is contained in:
parent
0ae3c5c609
commit
fd271ffe28
1 changed files with 51 additions and 24 deletions
|
@ -662,32 +662,59 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
tcx.features().generic_const_exprs,
|
tcx.features().generic_const_exprs,
|
||||||
"`ConstEquate` without a feature gate: {c1:?} {c2:?}",
|
"`ConstEquate` without a feature gate: {c1:?} {c2:?}",
|
||||||
);
|
);
|
||||||
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");
|
|
||||||
|
|
||||||
// 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(_), ty::ConstKind::Unevaluated(_)) =
|
|
||||||
(c1.kind(), c2.kind())
|
|
||||||
{
|
{
|
||||||
if let Ok(Some(a)) = tcx.expand_abstract_consts(c1)
|
let c1 =
|
||||||
&& let Ok(Some(b)) = tcx.expand_abstract_consts(c2)
|
if let Ok(Some(a)) = tcx.expand_abstract_consts(c1) { a } else { c1 };
|
||||||
&& a.ty() == b.ty()
|
let c2 =
|
||||||
&& let Ok(new_obligations) = self
|
if let Ok(Some(b)) = tcx.expand_abstract_consts(c2) { b } else { c2 };
|
||||||
.infcx
|
debug!(
|
||||||
.at(&obligation.cause, obligation.param_env)
|
"evalaute_predicate_recursively: equating consts:\nc1= {:?}\nc2= {:?}",
|
||||||
.eq(a, b)
|
c1, c2
|
||||||
{
|
);
|
||||||
let mut obligations = new_obligations.obligations;
|
|
||||||
self.add_depth(
|
use rustc_hir::def::DefKind;
|
||||||
obligations.iter_mut(),
|
use ty::ConstKind::Unevaluated;
|
||||||
obligation.recursion_depth,
|
match (c1.kind(), c2.kind()) {
|
||||||
);
|
(Unevaluated(a), Unevaluated(b))
|
||||||
return self.evaluate_predicates_recursively(
|
if a.def.did == b.def.did
|
||||||
previous_stack,
|
&& tcx.def_kind(a.def.did) == DefKind::AssocConst =>
|
||||||
obligations.into_iter(),
|
{
|
||||||
);
|
if let Ok(new_obligations) = self
|
||||||
|
.infcx
|
||||||
|
.at(&obligation.cause, obligation.param_env)
|
||||||
|
.trace(c1, c2)
|
||||||
|
.eq(a.substs, b.substs)
|
||||||
|
{
|
||||||
|
let mut obligations = new_obligations.obligations;
|
||||||
|
self.add_depth(
|
||||||
|
obligations.iter_mut(),
|
||||||
|
obligation.recursion_depth,
|
||||||
|
);
|
||||||
|
return self.evaluate_predicates_recursively(
|
||||||
|
previous_stack,
|
||||||
|
obligations.into_iter(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(_, Unevaluated(_)) | (Unevaluated(_), _) => (),
|
||||||
|
(_, _) => {
|
||||||
|
if let Ok(new_obligations) = self
|
||||||
|
.infcx
|
||||||
|
.at(&obligation.cause, obligation.param_env)
|
||||||
|
.eq(c1, c2)
|
||||||
|
{
|
||||||
|
let mut obligations = new_obligations.obligations;
|
||||||
|
self.add_depth(
|
||||||
|
obligations.iter_mut(),
|
||||||
|
obligation.recursion_depth,
|
||||||
|
);
|
||||||
|
return self.evaluate_predicates_recursively(
|
||||||
|
previous_stack,
|
||||||
|
obligations.into_iter(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue