Skip to content

Commit 44a2388

Browse files
committed
Make Ok value of repeat_while_none more general
1 parent 0b439b1 commit 44a2388

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -485,35 +485,38 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
485485
mut goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
486486
) -> Result<Certainty, NoSolution> {
487487
let mut new_goals = Vec::new();
488-
self.repeat_while_none(|this| {
489-
let mut has_changed = Err(Certainty::Yes);
490-
for goal in goals.drain(..) {
491-
let (changed, certainty) = match this.evaluate_goal(goal) {
492-
Ok(result) => result,
493-
Err(NoSolution) => return Some(Err(NoSolution)),
494-
};
495-
496-
if changed {
497-
has_changed = Ok(());
498-
}
488+
self.repeat_while_none(
489+
|_| Certainty::Maybe(MaybeCause::Overflow),
490+
|this| {
491+
let mut has_changed = Err(Certainty::Yes);
492+
for goal in goals.drain(..) {
493+
let (changed, certainty) = match this.evaluate_goal(goal) {
494+
Ok(result) => result,
495+
Err(NoSolution) => return Some(Err(NoSolution)),
496+
};
497+
498+
if changed {
499+
has_changed = Ok(());
500+
}
499501

500-
match certainty {
501-
Certainty::Yes => {}
502-
Certainty::Maybe(_) => {
503-
new_goals.push(goal);
504-
has_changed = has_changed.map_err(|c| c.unify_and(certainty));
502+
match certainty {
503+
Certainty::Yes => {}
504+
Certainty::Maybe(_) => {
505+
new_goals.push(goal);
506+
has_changed = has_changed.map_err(|c| c.unify_and(certainty));
507+
}
505508
}
506509
}
507-
}
508510

509-
match has_changed {
510-
Ok(()) => {
511-
mem::swap(&mut new_goals, &mut goals);
512-
None
511+
match has_changed {
512+
Ok(()) => {
513+
mem::swap(&mut new_goals, &mut goals);
514+
None
515+
}
516+
Err(certainty) => Some(Ok(certainty)),
513517
}
514-
Err(certainty) => Some(Ok(certainty)),
515-
}
516-
})
518+
},
519+
)
517520
}
518521

519522
// Recursively evaluates a list of goals to completion, making a query response.

compiler/rustc_trait_selection/src/solve/search_graph/overflow.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ impl<'tcx> SearchGraph<'tcx> {
6363

6464
impl<'tcx> EvalCtxt<'_, 'tcx> {
6565
/// A `while`-loop which tracks overflow.
66-
pub fn repeat_while_none(
66+
pub fn repeat_while_none<T>(
6767
&mut self,
68-
mut loop_body: impl FnMut(&mut Self) -> Option<Result<Certainty, NoSolution>>,
69-
) -> Result<Certainty, NoSolution> {
68+
mut overflow_body: impl FnMut(&mut Self) -> T,
69+
mut loop_body: impl FnMut(&mut Self) -> Option<Result<T, NoSolution>>,
70+
) -> Result<T, NoSolution> {
7071
let start_depth = self.search_graph.overflow_data.additional_depth;
7172
let depth = self.search_graph.stack.len();
7273
while !self.search_graph.overflow_data.has_overflow(depth) {
@@ -79,6 +80,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
7980
}
8081
self.search_graph.overflow_data.additional_depth = start_depth;
8182
self.search_graph.overflow_data.deal_with_overflow();
82-
Ok(Certainty::Maybe(MaybeCause::Overflow))
83+
Ok(overflow_body(self))
8384
}
8485
}

0 commit comments

Comments
 (0)