@@ -142,29 +142,17 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
142
142
}
143
143
144
144
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 ;
160
149
}
161
150
}
151
+ false
162
152
}
163
153
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)
168
156
}
169
157
170
158
/// Constructs the reduced graph for one item.
@@ -309,7 +297,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
309
297
let external_module = self . new_extern_crate_module ( parent_link, def) ;
310
298
self . define ( parent, name, TypeNS , ( external_module, sp) ) ;
311
299
312
- self . build_reduced_graph_for_external_crate ( & external_module) ;
300
+ self . build_reduced_graph_for_external_crate ( external_module) ;
313
301
}
314
302
parent
315
303
}
@@ -365,7 +353,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
365
353
for variant in & ( * enum_definition) . variants {
366
354
let item_def_id = self . ast_map . local_def_id ( item. id ) ;
367
355
self . build_reduced_graph_for_variant ( variant, item_def_id,
368
- & module, variant_modifiers) ;
356
+ module, variant_modifiers) ;
369
357
}
370
358
parent
371
359
}
@@ -421,7 +409,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
421
409
} ;
422
410
423
411
let modifiers = DefModifiers :: PUBLIC ; // NB: not DefModifiers::IMPORTABLE
424
- self . define ( & module_parent, item. name , ns, ( def, item. span , modifiers) ) ;
412
+ self . define ( module_parent, item. name , ns, ( def, item. span , modifiers) ) ;
425
413
426
414
self . trait_item_map . insert ( ( item. name , def_id) , item_def_id) ;
427
415
}
0 commit comments