@@ -801,9 +801,9 @@ pub struct ModuleS<'a> {
801801 resolutions : RefCell < HashMap < ( Name , Namespace ) , NameResolution < ' a > > > ,
802802 imports : RefCell < Vec < ImportDirective > > ,
803803
804- // The anonymous children of this node. Anonymous children are pseudo-
805- // modules that are implicitly created around items contained within
806- // blocks.
804+ // The module children of this node, including normal modules and anonymous modules.
805+ // Anonymous children are pseudo- modules that are implicitly created around items
806+ // contained within blocks.
807807 //
808808 // For example, if we have this:
809809 //
@@ -815,7 +815,7 @@ pub struct ModuleS<'a> {
815815 //
816816 // There will be an anonymous module created around `g` with the ID of the
817817 // entry block for `f`.
818- anonymous_children : RefCell < NodeMap < Module < ' a > > > ,
818+ module_children : RefCell < NodeMap < Module < ' a > > > ,
819819
820820 shadowed_traits : RefCell < Vec < & ' a NameBinding < ' a > > > ,
821821
@@ -848,7 +848,7 @@ impl<'a> ModuleS<'a> {
848848 is_extern_crate : false ,
849849 resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
850850 imports : RefCell :: new ( Vec :: new ( ) ) ,
851- anonymous_children : RefCell :: new ( NodeMap ( ) ) ,
851+ module_children : RefCell :: new ( NodeMap ( ) ) ,
852852 shadowed_traits : RefCell :: new ( Vec :: new ( ) ) ,
853853 glob_count : Cell :: new ( 0 ) ,
854854 pub_count : Cell :: new ( 0 ) ,
@@ -906,14 +906,6 @@ impl<'a> ModuleS<'a> {
906906 }
907907 }
908908
909- fn for_each_local_child < F : FnMut ( Name , Namespace , & ' a NameBinding < ' a > ) > ( & self , mut f : F ) {
910- self . for_each_child ( |name, ns, name_binding| {
911- if !name_binding. is_import ( ) && !name_binding. is_extern_crate ( ) {
912- f ( name, ns, name_binding)
913- }
914- } )
915- }
916-
917909 fn def_id ( & self ) -> Option < DefId > {
918910 self . def . as_ref ( ) . map ( Def :: def_id)
919911 }
@@ -1640,20 +1632,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16401632 }
16411633
16421634 // Descend into children and anonymous children.
1643- build_reduced_graph:: populate_module_if_necessary ( self , module_) ;
1644-
1645- module_. for_each_local_child ( |_, _, child_node| {
1646- match child_node. module ( ) {
1647- None => {
1648- // Continue.
1649- }
1650- Some ( child_module) => {
1651- self . report_unresolved_imports ( child_module) ;
1652- }
1653- }
1654- } ) ;
1655-
1656- for ( _, module_) in module_. anonymous_children . borrow ( ) . iter ( ) {
1635+ for ( _, module_) in module_. module_children . borrow ( ) . iter ( ) {
16571636 self . report_unresolved_imports ( module_) ;
16581637 }
16591638 }
@@ -1676,32 +1655,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16761655 // generate a fake "implementation scope" containing all the
16771656 // implementations thus found, for compatibility with old resolve pass.
16781657
1679- fn with_scope < F > ( & mut self , name : Option < Name > , f : F )
1658+ fn with_scope < F > ( & mut self , id : NodeId , f : F )
16801659 where F : FnOnce ( & mut Resolver )
16811660 {
16821661 let orig_module = self . current_module ;
16831662
16841663 // Move down in the graph.
1685- match name {
1686- None => {
1687- // Nothing to do.
1688- }
1689- Some ( name) => {
1690- build_reduced_graph:: populate_module_if_necessary ( self , & orig_module) ;
1691-
1692- if let Success ( name_binding) = orig_module. resolve_name ( name, TypeNS , false ) {
1693- match name_binding. module ( ) {
1694- None => {
1695- debug ! ( "!!! (with scope) didn't find module for `{}` in `{}`" ,
1696- name,
1697- module_to_string( orig_module) ) ;
1698- }
1699- Some ( module) => {
1700- self . current_module = module;
1701- }
1702- }
1703- }
1704- }
1664+ if let Some ( module) = orig_module. module_children . borrow ( ) . get ( & id) {
1665+ self . current_module = module;
17051666 }
17061667
17071668 f ( self ) ;
@@ -1825,7 +1786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18251786 }
18261787
18271788 ItemMod ( _) | ItemForeignMod ( _) => {
1828- self . with_scope ( Some ( name ) , |this| {
1789+ self . with_scope ( item . id , |this| {
18291790 intravisit:: walk_item ( this, item) ;
18301791 } ) ;
18311792 }
@@ -2261,7 +2222,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22612222 // Move down in the graph, if there's an anonymous module rooted here.
22622223 let orig_module = self . current_module ;
22632224 let anonymous_module =
2264- orig_module. anonymous_children . borrow ( ) . get ( & block. id ) . map ( |module| * module) ;
2225+ orig_module. module_children . borrow ( ) . get ( & block. id ) . map ( |module| * module) ;
22652226
22662227 if let Some ( anonymous_module) = anonymous_module {
22672228 debug ! ( "(resolving block) found anonymous module, moving down" ) ;
0 commit comments