Make Ok value of repeat_while_none more general
This commit is contained in:
parent
0b439b119b
commit
44a2388828
2 changed files with 31 additions and 27 deletions
|
@ -485,7 +485,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
mut goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
|
mut goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
|
||||||
) -> Result<Certainty, NoSolution> {
|
) -> Result<Certainty, NoSolution> {
|
||||||
let mut new_goals = Vec::new();
|
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);
|
let mut has_changed = Err(Certainty::Yes);
|
||||||
for goal in goals.drain(..) {
|
for goal in goals.drain(..) {
|
||||||
let (changed, certainty) = match this.evaluate_goal(goal) {
|
let (changed, certainty) = match this.evaluate_goal(goal) {
|
||||||
|
@ -513,7 +515,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
Err(certainty) => Some(Ok(certainty)),
|
Err(certainty) => Some(Ok(certainty)),
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively evaluates a list of goals to completion, making a query response.
|
// Recursively evaluates a list of goals to completion, making a query response.
|
||||||
|
|
|
@ -63,10 +63,11 @@ impl<'tcx> SearchGraph<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
/// A `while`-loop which tracks overflow.
|
/// A `while`-loop which tracks overflow.
|
||||||
pub fn repeat_while_none(
|
pub fn repeat_while_none<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut loop_body: impl FnMut(&mut Self) -> Option<Result<Certainty, NoSolution>>,
|
mut overflow_body: impl FnMut(&mut Self) -> T,
|
||||||
) -> Result<Certainty, NoSolution> {
|
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 start_depth = self.search_graph.overflow_data.additional_depth;
|
||||||
let depth = self.search_graph.stack.len();
|
let depth = self.search_graph.stack.len();
|
||||||
while !self.search_graph.overflow_data.has_overflow(depth) {
|
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.additional_depth = start_depth;
|
||||||
self.search_graph.overflow_data.deal_with_overflow();
|
self.search_graph.overflow_data.deal_with_overflow();
|
||||||
Ok(Certainty::Maybe(MaybeCause::Overflow))
|
Ok(overflow_body(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue