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,7 +485,9 @@ 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| {
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) {
@ -513,7 +515,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
Err(certainty) => Some(Ok(certainty)),
}
})
},
)
}
// Recursively evaluates a list of goals to completion, making a query response.

View file

@ -63,10 +63,11 @@ impl<'tcx> SearchGraph<'tcx> {
impl<'tcx> EvalCtxt<'_, 'tcx> {
/// A `while`-loop which tracks overflow.
pub fn repeat_while_none(
pub fn repeat_while_none<T>(
&mut self,
mut loop_body: impl FnMut(&mut Self) -> Option<Result<Certainty, NoSolution>>,
) -> Result<Certainty, NoSolution> {
mut overflow_body: impl FnMut(&mut Self) -> T,
mut loop_body: impl FnMut(&mut Self) -> Option<Result<T, NoSolution>>,
) -> Result<T, NoSolution> {
let start_depth = self.search_graph.overflow_data.additional_depth;
let depth = self.search_graph.stack.len();
while !self.search_graph.overflow_data.has_overflow(depth) {
@ -79,6 +80,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
self.search_graph.overflow_data.additional_depth = start_depth;
self.search_graph.overflow_data.deal_with_overflow();
Ok(Certainty::Maybe(MaybeCause::Overflow))
Ok(overflow_body(self))
}
}