]> git.proxmox.com Git - rustc.git/blob - src/librustc_data_structures/obligation_forest/mod.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / librustc_data_structures / obligation_forest / mod.rs
1 //! The `ObligationForest` is a utility data structure used in trait
2 //! matching to track the set of outstanding obligations (those not yet
3 //! resolved to success or error). It also tracks the "backtrace" of each
4 //! pending obligation (why we are trying to figure this out in the first
5 //! place).
6 //!
7 //! ### External view
8 //!
9 //! `ObligationForest` supports two main public operations (there are a
10 //! few others not discussed here):
11 //!
12 //! 1. Add a new root obligations (`register_obligation`).
13 //! 2. Process the pending obligations (`process_obligations`).
14 //!
15 //! When a new obligation `N` is added, it becomes the root of an
16 //! obligation tree. This tree can also carry some per-tree state `T`,
17 //! which is given at the same time. This tree is a singleton to start, so
18 //! `N` is both the root and the only leaf. Each time the
19 //! `process_obligations` method is called, it will invoke its callback
20 //! with every pending obligation (so that will include `N`, the first
21 //! time). The callback also receives a (mutable) reference to the
22 //! per-tree state `T`. The callback should process the obligation `O`
23 //! that it is given and return a `ProcessResult`:
24 //!
25 //! - `Unchanged` -> ambiguous result. Obligation was neither a success
26 //! nor a failure. It is assumed that further attempts to process the
27 //! obligation will yield the same result unless something in the
28 //! surrounding environment changes.
29 //! - `Changed(C)` - the obligation was *shallowly successful*. The
30 //! vector `C` is a list of subobligations. The meaning of this is that
31 //! `O` was successful on the assumption that all the obligations in `C`
32 //! are also successful. Therefore, `O` is only considered a "true"
33 //! success if `C` is empty. Otherwise, `O` is put into a suspended
34 //! state and the obligations in `C` become the new pending
35 //! obligations. They will be processed the next time you call
36 //! `process_obligations`.
37 //! - `Error(E)` -> obligation failed with error `E`. We will collect this
38 //! error and return it from `process_obligations`, along with the
39 //! "backtrace" of obligations (that is, the list of obligations up to
40 //! and including the root of the failed obligation). No further
41 //! obligations from that same tree will be processed, since the tree is
42 //! now considered to be in error.
43 //!
44 //! When the call to `process_obligations` completes, you get back an `Outcome`,
45 //! which includes three bits of information:
46 //!
47 //! - `completed`: a list of obligations where processing was fully
48 //! completed without error (meaning that all transitive subobligations
49 //! have also been completed). So, for example, if the callback from
50 //! `process_obligations` returns `Changed(C)` for some obligation `O`,
51 //! then `O` will be considered completed right away if `C` is the
52 //! empty vector. Otherwise it will only be considered completed once
53 //! all the obligations in `C` have been found completed.
54 //! - `errors`: a list of errors that occurred and associated backtraces
55 //! at the time of error, which can be used to give context to the user.
56 //! - `stalled`: if true, then none of the existing obligations were
57 //! *shallowly successful* (that is, no callback returned `Changed(_)`).
58 //! This implies that all obligations were either errors or returned an
59 //! ambiguous result, which means that any further calls to
60 //! `process_obligations` would simply yield back further ambiguous
61 //! results. This is used by the `FulfillmentContext` to decide when it
62 //! has reached a steady state.
63 //!
64 //! ### Implementation details
65 //!
66 //! For the most part, comments specific to the implementation are in the
67 //! code. This file only contains a very high-level overview. Basically,
68 //! the forest is stored in a vector. Each element of the vector is a node
69 //! in some tree. Each node in the vector has the index of its dependents,
70 //! including the first dependent which is known as the parent. It also
71 //! has a current state, described by `NodeState`. After each processing
72 //! step, we compress the vector to remove completed and error nodes, which
73 //! aren't needed anymore.
74
75 use crate::fx::{FxHashMap, FxHashSet};
76
77 use std::cell::Cell;
78 use std::collections::hash_map::Entry;
79 use std::fmt::Debug;
80 use std::hash;
81 use std::marker::PhantomData;
82
83 mod graphviz;
84
85 #[cfg(test)]
86 mod tests;
87
88 pub trait ForestObligation: Clone + Debug {
89 type CacheKey: Clone + hash::Hash + Eq + Debug;
90
91 /// Converts this `ForestObligation` suitable for use as a cache key.
92 /// If two distinct `ForestObligations`s return the same cache key,
93 /// then it must be sound to use the result of processing one obligation
94 /// (e.g. success for error) for the other obligation
95 fn as_cache_key(&self) -> Self::CacheKey;
96 }
97
98 pub trait ObligationProcessor {
99 type Obligation: ForestObligation;
100 type Error: Debug;
101
102 fn process_obligation(
103 &mut self,
104 obligation: &mut Self::Obligation,
105 ) -> ProcessResult<Self::Obligation, Self::Error>;
106
107 /// As we do the cycle check, we invoke this callback when we
108 /// encounter an actual cycle. `cycle` is an iterator that starts
109 /// at the start of the cycle in the stack and walks **toward the
110 /// top**.
111 ///
112 /// In other words, if we had O1 which required O2 which required
113 /// O3 which required O1, we would give an iterator yielding O1,
114 /// O2, O3 (O1 is not yielded twice).
115 fn process_backedge<'c, I>(&mut self, cycle: I, _marker: PhantomData<&'c Self::Obligation>)
116 where
117 I: Clone + Iterator<Item = &'c Self::Obligation>;
118 }
119
120 /// The result type used by `process_obligation`.
121 #[derive(Debug)]
122 pub enum ProcessResult<O, E> {
123 Unchanged,
124 Changed(Vec<O>),
125 Error(E),
126 }
127
128 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
129 struct ObligationTreeId(usize);
130
131 type ObligationTreeIdGenerator =
132 ::std::iter::Map<::std::ops::RangeFrom<usize>, fn(usize) -> ObligationTreeId>;
133
134 pub struct ObligationForest<O: ForestObligation> {
135 /// The list of obligations. In between calls to `process_obligations`,
136 /// this list only contains nodes in the `Pending` or `Waiting` state.
137 ///
138 /// `usize` indices are used here and throughout this module, rather than
139 /// `rustc_index::newtype_index!` indices, because this code is hot enough
140 /// that the `u32`-to-`usize` conversions that would be required are
141 /// significant, and space considerations are not important.
142 nodes: Vec<Node<O>>,
143
144 /// A cache of predicates that have been successfully completed.
145 done_cache: FxHashSet<O::CacheKey>,
146
147 /// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
148 /// its contents are not guaranteed to match those of `nodes`. See the
149 /// comments in `process_obligation` for details.
150 active_cache: FxHashMap<O::CacheKey, usize>,
151
152 /// A vector reused in compress(), to avoid allocating new vectors.
153 node_rewrites: Vec<usize>,
154
155 obligation_tree_id_generator: ObligationTreeIdGenerator,
156
157 /// Per tree error cache. This is used to deduplicate errors,
158 /// which is necessary to avoid trait resolution overflow in
159 /// some cases.
160 ///
161 /// See [this][details] for details.
162 ///
163 /// [details]: https://github.com/rust-lang/rust/pull/53255#issuecomment-421184780
164 error_cache: FxHashMap<ObligationTreeId, FxHashSet<O::CacheKey>>,
165 }
166
167 #[derive(Debug)]
168 struct Node<O> {
169 obligation: O,
170 state: Cell<NodeState>,
171
172 /// Obligations that depend on this obligation for their completion. They
173 /// must all be in a non-pending state.
174 dependents: Vec<usize>,
175
176 /// If true, `dependents[0]` points to a "parent" node, which requires
177 /// special treatment upon error but is otherwise treated the same.
178 /// (It would be more idiomatic to store the parent node in a separate
179 /// `Option<usize>` field, but that slows down the common case of
180 /// iterating over the parent and other descendants together.)
181 has_parent: bool,
182
183 /// Identifier of the obligation tree to which this node belongs.
184 obligation_tree_id: ObligationTreeId,
185 }
186
187 impl<O> Node<O> {
188 fn new(parent: Option<usize>, obligation: O, obligation_tree_id: ObligationTreeId) -> Node<O> {
189 Node {
190 obligation,
191 state: Cell::new(NodeState::Pending),
192 dependents: if let Some(parent_index) = parent { vec![parent_index] } else { vec![] },
193 has_parent: parent.is_some(),
194 obligation_tree_id,
195 }
196 }
197 }
198
199 /// The state of one node in some tree within the forest. This represents the
200 /// current state of processing for the obligation (of type `O`) associated
201 /// with this node.
202 ///
203 /// The non-`Error` state transitions are as follows.
204 /// ```
205 /// (Pre-creation)
206 /// |
207 /// | register_obligation_at() (called by process_obligations() and
208 /// v from outside the crate)
209 /// Pending
210 /// |
211 /// | process_obligations()
212 /// v
213 /// Success
214 /// | ^
215 /// | | mark_successes()
216 /// | v
217 /// | Waiting
218 /// |
219 /// | process_cycles()
220 /// v
221 /// Done
222 /// |
223 /// | compress()
224 /// v
225 /// (Removed)
226 /// ```
227 /// The `Error` state can be introduced in several places, via `error_at()`.
228 ///
229 /// Outside of `ObligationForest` methods, nodes should be either `Pending` or
230 /// `Waiting`.
231 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
232 enum NodeState {
233 /// This obligation has not yet been selected successfully. Cannot have
234 /// subobligations.
235 Pending,
236
237 /// This obligation was selected successfully, but may or may not have
238 /// subobligations.
239 Success,
240
241 /// This obligation was selected successfully, but it has a pending
242 /// subobligation.
243 Waiting,
244
245 /// This obligation, along with its subobligations, are complete, and will
246 /// be removed in the next collection.
247 Done,
248
249 /// This obligation was resolved to an error. It will be removed by the
250 /// next compression step.
251 Error,
252 }
253
254 #[derive(Debug)]
255 pub struct Outcome<O, E> {
256 /// Obligations that were completely evaluated, including all
257 /// (transitive) subobligations. Only computed if requested.
258 pub completed: Option<Vec<O>>,
259
260 /// Backtrace of obligations that were found to be in error.
261 pub errors: Vec<Error<O, E>>,
262
263 /// If true, then we saw no successful obligations, which means
264 /// there is no point in further iteration. This is based on the
265 /// assumption that when trait matching returns `Error` or
266 /// `Unchanged`, those results do not affect environmental
267 /// inference state. (Note that if we invoke `process_obligations`
268 /// with no pending obligations, stalled will be true.)
269 pub stalled: bool,
270 }
271
272 /// Should `process_obligations` compute the `Outcome::completed` field of its
273 /// result?
274 #[derive(PartialEq)]
275 pub enum DoCompleted {
276 No,
277 Yes,
278 }
279
280 #[derive(Debug, PartialEq, Eq)]
281 pub struct Error<O, E> {
282 pub error: E,
283 pub backtrace: Vec<O>,
284 }
285
286 impl<O: ForestObligation> ObligationForest<O> {
287 pub fn new() -> ObligationForest<O> {
288 ObligationForest {
289 nodes: vec![],
290 done_cache: Default::default(),
291 active_cache: Default::default(),
292 node_rewrites: vec![],
293 obligation_tree_id_generator: (0..).map(ObligationTreeId),
294 error_cache: Default::default(),
295 }
296 }
297
298 /// Returns the total number of nodes in the forest that have not
299 /// yet been fully resolved.
300 pub fn len(&self) -> usize {
301 self.nodes.len()
302 }
303
304 /// Registers an obligation.
305 pub fn register_obligation(&mut self, obligation: O) {
306 // Ignore errors here - there is no guarantee of success.
307 let _ = self.register_obligation_at(obligation, None);
308 }
309
310 // Returns Err(()) if we already know this obligation failed.
311 fn register_obligation_at(&mut self, obligation: O, parent: Option<usize>) -> Result<(), ()> {
312 if self.done_cache.contains(&obligation.as_cache_key()) {
313 debug!("register_obligation_at: ignoring already done obligation: {:?}", obligation);
314 return Ok(());
315 }
316
317 match self.active_cache.entry(obligation.as_cache_key()) {
318 Entry::Occupied(o) => {
319 let node = &mut self.nodes[*o.get()];
320 if let Some(parent_index) = parent {
321 // If the node is already in `active_cache`, it has already
322 // had its chance to be marked with a parent. So if it's
323 // not already present, just dump `parent` into the
324 // dependents as a non-parent.
325 if !node.dependents.contains(&parent_index) {
326 node.dependents.push(parent_index);
327 }
328 }
329 if let NodeState::Error = node.state.get() { Err(()) } else { Ok(()) }
330 }
331 Entry::Vacant(v) => {
332 let obligation_tree_id = match parent {
333 Some(parent_index) => self.nodes[parent_index].obligation_tree_id,
334 None => self.obligation_tree_id_generator.next().unwrap(),
335 };
336
337 let already_failed = parent.is_some()
338 && self
339 .error_cache
340 .get(&obligation_tree_id)
341 .map(|errors| errors.contains(&obligation.as_cache_key()))
342 .unwrap_or(false);
343
344 if already_failed {
345 Err(())
346 } else {
347 let new_index = self.nodes.len();
348 v.insert(new_index);
349 self.nodes.push(Node::new(parent, obligation, obligation_tree_id));
350 Ok(())
351 }
352 }
353 }
354 }
355
356 /// Converts all remaining obligations to the given error.
357 pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> {
358 let errors = self
359 .nodes
360 .iter()
361 .enumerate()
362 .filter(|(_index, node)| node.state.get() == NodeState::Pending)
363 .map(|(index, _node)| Error { error: error.clone(), backtrace: self.error_at(index) })
364 .collect();
365
366 let successful_obligations = self.compress(DoCompleted::Yes);
367 assert!(successful_obligations.unwrap().is_empty());
368 errors
369 }
370
371 /// Returns the set of obligations that are in a pending state.
372 pub fn map_pending_obligations<P, F>(&self, f: F) -> Vec<P>
373 where
374 F: Fn(&O) -> P,
375 {
376 self.nodes
377 .iter()
378 .filter(|node| node.state.get() == NodeState::Pending)
379 .map(|node| f(&node.obligation))
380 .collect()
381 }
382
383 fn insert_into_error_cache(&mut self, index: usize) {
384 let node = &self.nodes[index];
385 self.error_cache
386 .entry(node.obligation_tree_id)
387 .or_default()
388 .insert(node.obligation.as_cache_key());
389 }
390
391 /// Performs a pass through the obligation list. This must
392 /// be called in a loop until `outcome.stalled` is false.
393 ///
394 /// This _cannot_ be unrolled (presently, at least).
395 pub fn process_obligations<P>(
396 &mut self,
397 processor: &mut P,
398 do_completed: DoCompleted,
399 ) -> Outcome<O, P::Error>
400 where
401 P: ObligationProcessor<Obligation = O>,
402 {
403 let mut errors = vec![];
404 let mut stalled = true;
405
406 // Note that the loop body can append new nodes, and those new nodes
407 // will then be processed by subsequent iterations of the loop.
408 //
409 // We can't use an iterator for the loop because `self.nodes` is
410 // appended to and the borrow checker would complain. We also can't use
411 // `for index in 0..self.nodes.len() { ... }` because the range would
412 // be computed with the initial length, and we would miss the appended
413 // nodes. Therefore we use a `while` loop.
414 let mut index = 0;
415 while let Some(node) = self.nodes.get_mut(index) {
416 // `processor.process_obligation` can modify the predicate within
417 // `node.obligation`, and that predicate is the key used for
418 // `self.active_cache`. This means that `self.active_cache` can get
419 // out of sync with `nodes`. It's not very common, but it does
420 // happen, and code in `compress` has to allow for it.
421 if node.state.get() != NodeState::Pending {
422 index += 1;
423 continue;
424 }
425
426 match processor.process_obligation(&mut node.obligation) {
427 ProcessResult::Unchanged => {
428 // No change in state.
429 }
430 ProcessResult::Changed(children) => {
431 // We are not (yet) stalled.
432 stalled = false;
433 node.state.set(NodeState::Success);
434
435 for child in children {
436 let st = self.register_obligation_at(child, Some(index));
437 if let Err(()) = st {
438 // Error already reported - propagate it
439 // to our node.
440 self.error_at(index);
441 }
442 }
443 }
444 ProcessResult::Error(err) => {
445 stalled = false;
446 errors.push(Error { error: err, backtrace: self.error_at(index) });
447 }
448 }
449 index += 1;
450 }
451
452 if stalled {
453 // There's no need to perform marking, cycle processing and compression when nothing
454 // changed.
455 return Outcome {
456 completed: if do_completed == DoCompleted::Yes { Some(vec![]) } else { None },
457 errors,
458 stalled,
459 };
460 }
461
462 self.mark_successes();
463 self.process_cycles(processor);
464 let completed = self.compress(do_completed);
465
466 Outcome { completed, errors, stalled }
467 }
468
469 /// Returns a vector of obligations for `p` and all of its
470 /// ancestors, putting them into the error state in the process.
471 fn error_at(&self, mut index: usize) -> Vec<O> {
472 let mut error_stack: Vec<usize> = vec![];
473 let mut trace = vec![];
474
475 loop {
476 let node = &self.nodes[index];
477 node.state.set(NodeState::Error);
478 trace.push(node.obligation.clone());
479 if node.has_parent {
480 // The first dependent is the parent, which is treated
481 // specially.
482 error_stack.extend(node.dependents.iter().skip(1));
483 index = node.dependents[0];
484 } else {
485 // No parent; treat all dependents non-specially.
486 error_stack.extend(node.dependents.iter());
487 break;
488 }
489 }
490
491 while let Some(index) = error_stack.pop() {
492 let node = &self.nodes[index];
493 if node.state.get() != NodeState::Error {
494 node.state.set(NodeState::Error);
495 error_stack.extend(node.dependents.iter());
496 }
497 }
498
499 trace
500 }
501
502 /// Mark all `Waiting` nodes as `Success`, except those that depend on a
503 /// pending node.
504 fn mark_successes(&self) {
505 // Convert all `Waiting` nodes to `Success`.
506 for node in &self.nodes {
507 if node.state.get() == NodeState::Waiting {
508 node.state.set(NodeState::Success);
509 }
510 }
511
512 // Convert `Success` nodes that depend on a pending node back to
513 // `Waiting`.
514 for node in &self.nodes {
515 if node.state.get() == NodeState::Pending {
516 // This call site is hot.
517 self.inlined_mark_dependents_as_waiting(node);
518 }
519 }
520 }
521
522 // This always-inlined function is for the hot call site.
523 #[inline(always)]
524 fn inlined_mark_dependents_as_waiting(&self, node: &Node<O>) {
525 for &index in node.dependents.iter() {
526 let node = &self.nodes[index];
527 let state = node.state.get();
528 if state == NodeState::Success {
529 node.state.set(NodeState::Waiting);
530 // This call site is cold.
531 self.uninlined_mark_dependents_as_waiting(node);
532 } else {
533 debug_assert!(state == NodeState::Waiting || state == NodeState::Error)
534 }
535 }
536 }
537
538 // This never-inlined function is for the cold call site.
539 #[inline(never)]
540 fn uninlined_mark_dependents_as_waiting(&self, node: &Node<O>) {
541 self.inlined_mark_dependents_as_waiting(node)
542 }
543
544 /// Report cycles between all `Success` nodes, and convert all `Success`
545 /// nodes to `Done`. This must be called after `mark_successes`.
546 fn process_cycles<P>(&self, processor: &mut P)
547 where
548 P: ObligationProcessor<Obligation = O>,
549 {
550 let mut stack = vec![];
551
552 for (index, node) in self.nodes.iter().enumerate() {
553 // For some benchmarks this state test is extremely hot. It's a win
554 // to handle the no-op cases immediately to avoid the cost of the
555 // function call.
556 if node.state.get() == NodeState::Success {
557 self.find_cycles_from_node(&mut stack, processor, index);
558 }
559 }
560
561 debug_assert!(stack.is_empty());
562 }
563
564 fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
565 where
566 P: ObligationProcessor<Obligation = O>,
567 {
568 let node = &self.nodes[index];
569 if node.state.get() == NodeState::Success {
570 match stack.iter().rposition(|&n| n == index) {
571 None => {
572 stack.push(index);
573 for &dep_index in node.dependents.iter() {
574 self.find_cycles_from_node(stack, processor, dep_index);
575 }
576 stack.pop();
577 node.state.set(NodeState::Done);
578 }
579 Some(rpos) => {
580 // Cycle detected.
581 processor.process_backedge(
582 stack[rpos..].iter().map(GetObligation(&self.nodes)),
583 PhantomData,
584 );
585 }
586 }
587 }
588 }
589
590 /// Compresses the vector, removing all popped nodes. This adjusts the
591 /// indices and hence invalidates any outstanding indices. `process_cycles`
592 /// must be run beforehand to remove any cycles on `Success` nodes.
593 #[inline(never)]
594 fn compress(&mut self, do_completed: DoCompleted) -> Option<Vec<O>> {
595 let orig_nodes_len = self.nodes.len();
596 let mut node_rewrites: Vec<_> = std::mem::take(&mut self.node_rewrites);
597 debug_assert!(node_rewrites.is_empty());
598 node_rewrites.extend(0..orig_nodes_len);
599 let mut dead_nodes = 0;
600 let mut removed_done_obligations: Vec<O> = vec![];
601
602 // Move removable nodes to the end, preserving the order of the
603 // remaining nodes.
604 //
605 // LOOP INVARIANT:
606 // self.nodes[0..index - dead_nodes] are the first remaining nodes
607 // self.nodes[index - dead_nodes..index] are all dead
608 // self.nodes[index..] are unchanged
609 for index in 0..orig_nodes_len {
610 let node = &self.nodes[index];
611 match node.state.get() {
612 NodeState::Pending | NodeState::Waiting => {
613 if dead_nodes > 0 {
614 self.nodes.swap(index, index - dead_nodes);
615 node_rewrites[index] -= dead_nodes;
616 }
617 }
618 NodeState::Done => {
619 // This lookup can fail because the contents of
620 // `self.active_cache` are not guaranteed to match those of
621 // `self.nodes`. See the comment in `process_obligation`
622 // for more details.
623 if let Some((predicate, _)) =
624 self.active_cache.remove_entry(&node.obligation.as_cache_key())
625 {
626 self.done_cache.insert(predicate);
627 } else {
628 self.done_cache.insert(node.obligation.as_cache_key().clone());
629 }
630 if do_completed == DoCompleted::Yes {
631 // Extract the success stories.
632 removed_done_obligations.push(node.obligation.clone());
633 }
634 node_rewrites[index] = orig_nodes_len;
635 dead_nodes += 1;
636 }
637 NodeState::Error => {
638 // We *intentionally* remove the node from the cache at this point. Otherwise
639 // tests must come up with a different type on every type error they
640 // check against.
641 self.active_cache.remove(&node.obligation.as_cache_key());
642 self.insert_into_error_cache(index);
643 node_rewrites[index] = orig_nodes_len;
644 dead_nodes += 1;
645 }
646 NodeState::Success => unreachable!(),
647 }
648 }
649
650 if dead_nodes > 0 {
651 // Remove the dead nodes and rewrite indices.
652 self.nodes.truncate(orig_nodes_len - dead_nodes);
653 self.apply_rewrites(&node_rewrites);
654 }
655
656 node_rewrites.truncate(0);
657 self.node_rewrites = node_rewrites;
658
659 if do_completed == DoCompleted::Yes { Some(removed_done_obligations) } else { None }
660 }
661
662 fn apply_rewrites(&mut self, node_rewrites: &[usize]) {
663 let orig_nodes_len = node_rewrites.len();
664
665 for node in &mut self.nodes {
666 let mut i = 0;
667 while let Some(dependent) = node.dependents.get_mut(i) {
668 let new_index = node_rewrites[*dependent];
669 if new_index >= orig_nodes_len {
670 node.dependents.swap_remove(i);
671 if i == 0 && node.has_parent {
672 // We just removed the parent.
673 node.has_parent = false;
674 }
675 } else {
676 *dependent = new_index;
677 i += 1;
678 }
679 }
680 }
681
682 // This updating of `self.active_cache` is necessary because the
683 // removal of nodes within `compress` can fail. See above.
684 self.active_cache.retain(|_predicate, index| {
685 let new_index = node_rewrites[*index];
686 if new_index >= orig_nodes_len {
687 false
688 } else {
689 *index = new_index;
690 true
691 }
692 });
693 }
694 }
695
696 // I need a Clone closure.
697 #[derive(Clone)]
698 struct GetObligation<'a, O>(&'a [Node<O>]);
699
700 impl<'a, 'b, O> FnOnce<(&'b usize,)> for GetObligation<'a, O> {
701 type Output = &'a O;
702 extern "rust-call" fn call_once(self, args: (&'b usize,)) -> &'a O {
703 &self.0[*args.0].obligation
704 }
705 }
706
707 impl<'a, 'b, O> FnMut<(&'b usize,)> for GetObligation<'a, O> {
708 extern "rust-call" fn call_mut(&mut self, args: (&'b usize,)) -> &'a O {
709 &self.0[*args.0].obligation
710 }
711 }