From 23bdbb13f4087751d7310ae896ccd3e1ae690abb Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 27 Jan 2016 10:51:22 +0000 Subject: [PATCH] Refactor block_needs_anonymous_module --- src/librustc_resolve/build_reduced_graph.rs | 26 ++++++--------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 8f4913f0420..e84525ca296 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -142,29 +142,17 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { } fn block_needs_anonymous_module(&mut self, block: &Block) -> bool { - // Check each statement. - for statement in &block.stmts { - match statement.node { - StmtDecl(ref declaration, _) => { - match declaration.node { - DeclItem(_) => { - return true; - } - _ => { - // Keep searching. - } - } - } - _ => { - // Keep searching. + fn is_item(statement: &hir::Stmt) -> bool { + if let StmtDecl(ref declaration, _) = statement.node { + if let DeclItem(_) = declaration.node { + return true; } } + false } - // If we found no items, we don't need to create - // an anonymous module. - - return false; + // If any statements are items, we need to create an anonymous module + block.stmts.iter().any(is_item) } /// Constructs the reduced graph for one item.