diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-09-24 18:22:55 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-09-30 05:23:07 +1000 |
| commit | ea726501e1b86d8efa5c800a7a218aed7ee1503c (patch) | |
| tree | 5ff34d1f064c5fa26b7bb6b3ade9557d210367b0 | |
| parent | 7130e6c0733ca4e6d8fc1dd08a882ff3547c94ba (diff) | |
| download | rust-ea726501e1b86d8efa5c800a7a218aed7ee1503c.tar.gz rust-ea726501e1b86d8efa5c800a7a218aed7ee1503c.zip | |
Use `filter` and `map` in `to_errors`.
| -rw-r--r-- | src/librustc_data_structures/obligation_forest/mod.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 77eb0beeec3..ccc8aa288d4 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -348,15 +348,16 @@ impl<O: ForestObligation> ObligationForest<O> { /// Converts all remaining obligations to the given error. pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> { - let mut errors = vec![]; - for (index, node) in self.nodes.iter().enumerate() { - if let NodeState::Pending = node.state.get() { - errors.push(Error { + let errors = self.nodes.iter().enumerate() + .filter(|(_index, node)| node.state.get() == NodeState::Pending) + .map(|(index, _node)| { + Error { error: error.clone(), backtrace: self.error_at(index), - }); - } - } + } + }) + .collect(); + let successful_obligations = self.compress(DoCompleted::Yes); assert!(successful_obligations.unwrap().is_empty()); errors @@ -366,10 +367,9 @@ impl<O: ForestObligation> ObligationForest<O> { pub fn map_pending_obligations<P, F>(&self, f: F) -> Vec<P> where F: Fn(&O) -> P { - self.nodes - .iter() - .filter(|n| n.state.get() == NodeState::Pending) - .map(|n| f(&n.obligation)) + self.nodes.iter() + .filter(|node| node.state.get() == NodeState::Pending) + .map(|node| f(&node.obligation)) .collect() } |
