Skip to content

Commit ea72650

Browse files
committed
Use filter and map in to_errors.
1 parent 7130e6c commit ea72650

File tree

1 file changed

+11
-11
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+11
-11
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,16 @@ impl<O: ForestObligation> ObligationForest<O> {
348348

349349
/// Converts all remaining obligations to the given error.
350350
pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> {
351-
let mut errors = vec![];
352-
for (index, node) in self.nodes.iter().enumerate() {
353-
if let NodeState::Pending = node.state.get() {
354-
errors.push(Error {
351+
let errors = self.nodes.iter().enumerate()
352+
.filter(|(_index, node)| node.state.get() == NodeState::Pending)
353+
.map(|(index, _node)| {
354+
Error {
355355
error: error.clone(),
356356
backtrace: self.error_at(index),
357-
});
358-
}
359-
}
357+
}
358+
})
359+
.collect();
360+
360361
let successful_obligations = self.compress(DoCompleted::Yes);
361362
assert!(successful_obligations.unwrap().is_empty());
362363
errors
@@ -366,10 +367,9 @@ impl<O: ForestObligation> ObligationForest<O> {
366367
pub fn map_pending_obligations<P, F>(&self, f: F) -> Vec<P>
367368
where F: Fn(&O) -> P
368369
{
369-
self.nodes
370-
.iter()
371-
.filter(|n| n.state.get() == NodeState::Pending)
372-
.map(|n| f(&n.obligation))
370+
self.nodes.iter()
371+
.filter(|node| node.state.get() == NodeState::Pending)
372+
.map(|node| f(&node.obligation))
373373
.collect()
374374
}
375375

0 commit comments

Comments
 (0)