about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-09-24 18:22:55 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2019-09-30 05:23:07 +1000
commitea726501e1b86d8efa5c800a7a218aed7ee1503c (patch)
tree5ff34d1f064c5fa26b7bb6b3ade9557d210367b0
parent7130e6c0733ca4e6d8fc1dd08a882ff3547c94ba (diff)
downloadrust-ea726501e1b86d8efa5c800a7a218aed7ee1503c.tar.gz
rust-ea726501e1b86d8efa5c800a7a218aed7ee1503c.zip
Use `filter` and `map` in `to_errors`.
-rw-r--r--src/librustc_data_structures/obligation_forest/mod.rs22
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()
     }