review nits

This commit is contained in:
Boxy 2023-03-17 13:33:27 +00:00
parent ed63201224
commit ee31e5fc57
2 changed files with 18 additions and 14 deletions

View File

@ -35,6 +35,12 @@ pub struct EvalCtxt<'a, 'tcx> {
pub(super) nested_goals: NestedGoals<'tcx>, pub(super) nested_goals: NestedGoals<'tcx>,
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(super) enum IsNormalizesToHack {
Yes,
No,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(super) struct NestedGoals<'tcx> { pub(super) struct NestedGoals<'tcx> {
pub(super) projection_eq_hack_goal: Option<Goal<'tcx, ty::ProjectionPredicate<'tcx>>>, pub(super) projection_eq_hack_goal: Option<Goal<'tcx, ty::ProjectionPredicate<'tcx>>>,

View File

@ -45,7 +45,7 @@ mod trait_goals;
pub use eval_ctxt::EvalCtxt; pub use eval_ctxt::EvalCtxt;
pub use fulfill::FulfillmentCtxt; pub use fulfill::FulfillmentCtxt;
use self::eval_ctxt::NestedGoals; use self::eval_ctxt::{IsNormalizesToHack, NestedGoals};
trait CanonicalResponseExt { trait CanonicalResponseExt {
fn has_no_inference_or_external_constraints(&self) -> bool; fn has_no_inference_or_external_constraints(&self) -> bool;
@ -86,7 +86,7 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
var_values: CanonicalVarValues::dummy(), var_values: CanonicalVarValues::dummy(),
nested_goals: NestedGoals::new(), nested_goals: NestedGoals::new(),
} }
.evaluate_goal(false, goal); .evaluate_goal(IsNormalizesToHack::No, goal);
assert!(search_graph.is_empty()); assert!(search_graph.is_empty());
result result
@ -130,7 +130,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
/// been constrained and the certainty of the result. /// been constrained and the certainty of the result.
fn evaluate_goal( fn evaluate_goal(
&mut self, &mut self,
is_projection_eq_hack_goal: bool, is_normalizes_to_hack: IsNormalizesToHack,
goal: Goal<'tcx, ty::Predicate<'tcx>>, goal: Goal<'tcx, ty::Predicate<'tcx>>,
) -> Result<(bool, Certainty), NoSolution> { ) -> Result<(bool, Certainty), NoSolution> {
let (orig_values, canonical_goal) = self.canonicalize_goal(goal); let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
@ -153,7 +153,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
// solver cycle. // solver cycle.
if cfg!(debug_assertions) if cfg!(debug_assertions)
&& has_changed && has_changed
&& !is_projection_eq_hack_goal && is_normalizes_to_hack == IsNormalizesToHack::No
&& !self.search_graph.in_cycle() && !self.search_graph.in_cycle()
{ {
debug!("rerunning goal to check result is stable"); debug!("rerunning goal to check result is stable");
@ -223,11 +223,8 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
} else { } else {
let kind = self.infcx.instantiate_binder_with_placeholders(kind); let kind = self.infcx.instantiate_binder_with_placeholders(kind);
let goal = goal.with(self.tcx(), ty::Binder::dummy(kind)); let goal = goal.with(self.tcx(), ty::Binder::dummy(kind));
// `false` is fine to use as if this were a projection goal from the hack there would not be self.add_goal(goal);
// a binder as the real projection goal that is the parent of the hack goal would have already self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
// had its binder replaced with placeholders.
let (_, certainty) = self.evaluate_goal(false, goal)?;
self.evaluate_added_goals_and_make_canonical_response(certainty)
} }
} }
@ -436,7 +433,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
if let Some(goal) = goals.projection_eq_hack_goal.take() { if let Some(goal) = goals.projection_eq_hack_goal.take() {
let (_, certainty) = match this.evaluate_goal( let (_, certainty) = match this.evaluate_goal(
true, IsNormalizesToHack::Yes,
goal.with(this.tcx(), ty::Binder::dummy(goal.predicate)), goal.with(this.tcx(), ty::Binder::dummy(goal.predicate)),
) { ) {
Ok(r) => r, Ok(r) => r,
@ -480,10 +477,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
} }
for nested_goal in goals.goals.drain(..) { for nested_goal in goals.goals.drain(..) {
let (changed, certainty) = match this.evaluate_goal(false, nested_goal) { let (changed, certainty) =
Ok(result) => result, match this.evaluate_goal(IsNormalizesToHack::No, nested_goal) {
Err(NoSolution) => return Some(Err(NoSolution)), Ok(result) => result,
}; Err(NoSolution) => return Some(Err(NoSolution)),
};
if changed { if changed {
has_changed = Ok(()); has_changed = Ok(());