|
2 | 2 |
|
3 | 3 | mod errors; |
4 | 4 |
|
5 | | -use std::{mem, ops::ControlFlow}; |
| 5 | +use std::ops::ControlFlow; |
6 | 6 |
|
7 | 7 | use rustc_hash::FxHashSet; |
8 | 8 | use rustc_next_trait_solver::{ |
@@ -77,14 +77,12 @@ impl<'db> ObligationStorage<'db> { |
77 | 77 | obligations |
78 | 78 | } |
79 | 79 |
|
80 | | - fn drain_pending( |
81 | | - &mut self, |
82 | | - cond: impl Fn(&PredicateObligation<'db>) -> bool, |
83 | | - ) -> PendingObligations<'db> { |
84 | | - let (not_stalled, pending) = |
85 | | - mem::take(&mut self.pending).into_iter().partition(|(o, _)| cond(o)); |
86 | | - self.pending = pending; |
87 | | - not_stalled |
| 80 | + fn drain_pending<'this, 'cond>( |
| 81 | + &'this mut self, |
| 82 | + cond: impl 'cond + Fn(&PredicateObligation<'db>) -> bool, |
| 83 | + ) -> impl Iterator<Item = (PredicateObligation<'db>, Option<GoalStalledOn<DbInterner<'db>>>)> |
| 84 | + { |
| 85 | + self.pending.extract_if(.., move |(o, _)| cond(o)) |
88 | 86 | } |
89 | 87 |
|
90 | 88 | fn on_fulfillment_overflow(&mut self, infcx: &InferCtxt<'db>) { |
@@ -165,9 +163,11 @@ impl<'db> FulfillmentCtxt<'db> { |
165 | 163 | // to not put the obligations queue in `InferenceTable`'s snapshots. |
166 | 164 | // assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots()); |
167 | 165 | let mut errors = Vec::new(); |
| 166 | + let mut obligations = Vec::new(); |
168 | 167 | loop { |
169 | 168 | let mut any_changed = false; |
170 | | - for (mut obligation, stalled_on) in self.obligations.drain_pending(|_| true) { |
| 169 | + obligations.extend(self.obligations.drain_pending(|_| true)); |
| 170 | + for (mut obligation, stalled_on) in obligations.drain(..) { |
171 | 171 | if obligation.recursion_depth >= infcx.interner.recursion_limit() { |
172 | 172 | self.obligations.on_fulfillment_overflow(infcx); |
173 | 173 | // Only return true errors that we have accumulated while processing. |
@@ -269,7 +269,6 @@ impl<'db> FulfillmentCtxt<'db> { |
269 | 269 | .is_break() |
270 | 270 | }) |
271 | 271 | }) |
272 | | - .into_iter() |
273 | 272 | .map(|(o, _)| o) |
274 | 273 | .collect() |
275 | 274 | } |
|
0 commit comments