@@ -801,9 +801,9 @@ pub struct ModuleS<'a> {
801
801
resolutions : RefCell < HashMap < ( Name , Namespace ) , NameResolution < ' a > > > ,
802
802
imports : RefCell < Vec < ImportDirective > > ,
803
803
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.
807
807
//
808
808
// For example, if we have this:
809
809
//
@@ -815,7 +815,7 @@ pub struct ModuleS<'a> {
815
815
//
816
816
// There will be an anonymous module created around `g` with the ID of the
817
817
// entry block for `f`.
818
- anonymous_children : RefCell < NodeMap < Module < ' a > > > ,
818
+ module_children : RefCell < NodeMap < Module < ' a > > > ,
819
819
820
820
shadowed_traits : RefCell < Vec < & ' a NameBinding < ' a > > > ,
821
821
@@ -848,7 +848,7 @@ impl<'a> ModuleS<'a> {
848
848
is_extern_crate : false ,
849
849
resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
850
850
imports : RefCell :: new ( Vec :: new ( ) ) ,
851
- anonymous_children : RefCell :: new ( NodeMap ( ) ) ,
851
+ module_children : RefCell :: new ( NodeMap ( ) ) ,
852
852
shadowed_traits : RefCell :: new ( Vec :: new ( ) ) ,
853
853
glob_count : Cell :: new ( 0 ) ,
854
854
pub_count : Cell :: new ( 0 ) ,
@@ -906,14 +906,6 @@ impl<'a> ModuleS<'a> {
906
906
}
907
907
}
908
908
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
-
917
909
fn def_id ( & self ) -> Option < DefId > {
918
910
self . def . as_ref ( ) . map ( Def :: def_id)
919
911
}
@@ -1640,20 +1632,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1640
1632
}
1641
1633
1642
1634
// 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 ( ) {
1657
1636
self . report_unresolved_imports ( module_) ;
1658
1637
}
1659
1638
}
@@ -1676,32 +1655,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1676
1655
// generate a fake "implementation scope" containing all the
1677
1656
// implementations thus found, for compatibility with old resolve pass.
1678
1657
1679
- fn with_scope < F > ( & mut self , name : Option < Name > , f : F )
1658
+ fn with_scope < F > ( & mut self , id : NodeId , f : F )
1680
1659
where F : FnOnce ( & mut Resolver )
1681
1660
{
1682
1661
let orig_module = self . current_module ;
1683
1662
1684
1663
// 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;
1705
1666
}
1706
1667
1707
1668
f ( self ) ;
@@ -1825,7 +1786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1825
1786
}
1826
1787
1827
1788
ItemMod ( _) | ItemForeignMod ( _) => {
1828
- self . with_scope ( Some ( name ) , |this| {
1789
+ self . with_scope ( item . id , |this| {
1829
1790
intravisit:: walk_item ( this, item) ;
1830
1791
} ) ;
1831
1792
}
@@ -2261,7 +2222,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2261
2222
// Move down in the graph, if there's an anonymous module rooted here.
2262
2223
let orig_module = self . current_module ;
2263
2224
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) ;
2265
2226
2266
2227
if let Some ( anonymous_module) = anonymous_module {
2267
2228
debug ! ( "(resolving block) found anonymous module, moving down" ) ;
0 commit comments