Add expand_abstract_const

Adds the ability to directly expand a const to an expr without having to deal with intermediate
steps.
This commit is contained in:
kadmin 2022-10-25 08:16:43 +00:00
parent f9750c1554
commit 5bb1a9febc
11 changed files with 124 additions and 174 deletions

View file

@ -668,19 +668,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// if the constants depend on generic parameters.
//
// Let's just see where this breaks :shrug:
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
if let (ty::ConstKind::Unevaluated(_), ty::ConstKind::Unevaluated(_)) =
(c1.kind(), c2.kind())
{
if let (Ok(Some(a)), Ok(Some(b))) = (
tcx.expand_bound_abstract_const(
tcx.bound_abstract_const(a.def),
a.substs,
),
tcx.expand_bound_abstract_const(
tcx.bound_abstract_const(b.def),
b.substs,
),
) && a.ty() == b.ty() && let Ok(new_obligations) =
tcx.expand_abstract_consts(c1),
tcx.expand_abstract_consts(c2),
) && a.ty() == b.ty() && let Ok(new_obligations) =
self.infcx.at(&obligation.cause, obligation.param_env).eq(a, b)
{
let mut obligations = new_obligations.obligations;
@ -718,7 +712,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{
Ok(_) => Ok(EvaluatedToOk),
Ok(inf_ok) => self.evaluate_predicates_recursively(
previous_stack,
inf_ok.into_obligations(),
),
Err(_) => Ok(EvaluatedToErr),
}
}