Skip to content

Commit 23bdbb1

Browse files
committed
Refactor block_needs_anonymous_module
1 parent 2ed210d commit 23bdbb1

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,17 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
142142
}
143143

144144
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
145-
// Check each statement.
146-
for statement in &block.stmts {
147-
match statement.node {
148-
StmtDecl(ref declaration, _) => {
149-
match declaration.node {
150-
DeclItem(_) => {
151-
return true;
152-
}
153-
_ => {
154-
// Keep searching.
155-
}
156-
}
157-
}
158-
_ => {
159-
// Keep searching.
145+
fn is_item(statement: &hir::Stmt) -> bool {
146+
if let StmtDecl(ref declaration, _) = statement.node {
147+
if let DeclItem(_) = declaration.node {
148+
return true;
160149
}
161150
}
151+
false
162152
}
163153

164-
// If we found no items, we don't need to create
165-
// an anonymous module.
166-
167-
return false;
154+
// If any statements are items, we need to create an anonymous module
155+
block.stmts.iter().any(is_item)
168156
}
169157

170158
/// Constructs the reduced graph for one item.

0 commit comments

Comments
 (0)