1
Fork 0

Make Ok value of repeat_while_none more general

This commit is contained in:
Santiago Pastorino 2023-01-31 13:42:00 -03:00
parent 0b439b119b
commit 44a2388828
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
2 changed files with 31 additions and 27 deletions

View file

@ -485,35 +485,38 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
mut goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
) -> Result<Certainty, NoSolution> {
let mut new_goals = Vec::new();
self.repeat_while_none(|this| {
let mut has_changed = Err(Certainty::Yes);
for goal in goals.drain(..) {
let (changed, certainty) = match this.evaluate_goal(goal) {
Ok(result) => result,
Err(NoSolution) => return Some(Err(NoSolution)),
};
self.repeat_while_none(
|_| Certainty::Maybe(MaybeCause::Overflow),
|this| {
let mut has_changed = Err(Certainty::Yes);
for goal in goals.drain(..) {
let (changed, certainty) = match this.evaluate_goal(goal) {
Ok(result) => result,
Err(NoSolution) => return Some(Err(NoSolution)),
};
if changed {
has_changed = Ok(());
}
if changed {
has_changed = Ok(());
}
match certainty {
Certainty::Yes => {}
Certainty::Maybe(_) => {
new_goals.push(goal);
has_changed = has_changed.map_err(|c| c.unify_and(certainty));
match certainty {
Certainty::Yes => {}
Certainty::Maybe(_) => {
new_goals.push(goal);
has_changed = has_changed.map_err(|c| c.unify_and(certainty));
}
}
}
}
match has_changed {
Ok(()) => {
mem::swap(&mut new_goals, &mut goals);
None
match has_changed {
Ok(()) => {
mem::swap(&mut new_goals, &mut goals);
None
}
Err(certainty) => Some(Ok(certainty)),
}
Err(certainty) => Some(Ok(certainty)),
}
})
},
)
}
// Recursively evaluates a list of goals to completion, making a query response.