@@ -1145,6 +1145,8 @@ pub struct Resolver<'ra, 'tcx> {
11451145/// some AST passes can generate identifiers that only resolve to local or 
11461146/// lang items. 
11471147empty_module :  Module < ' ra > , 
1148+     /// All local modules, including blocks. 
1149+ local_modules :  Vec < Module < ' ra > > , 
11481150    /// Eagerly populated map of all local non-block modules. 
11491151local_module_map :  FxIndexMap < LocalDefId ,  Module < ' ra > > , 
11501152    /// Lazily populated cache of modules loaded from external crates. 
@@ -1298,7 +1300,6 @@ pub struct Resolver<'ra, 'tcx> {
12981300#[ derive( Default ) ]  
12991301pub  struct  ResolverArenas < ' ra >  { 
13001302    modules :  TypedArena < ModuleData < ' ra > > , 
1301-     local_modules :  RefCell < Vec < Module < ' ra > > > , 
13021303    imports :  TypedArena < ImportData < ' ra > > , 
13031304    name_resolutions :  TypedArena < RefCell < NameResolution < ' ra > > > , 
13041305    ast_paths :  TypedArena < ast:: Path > , 
@@ -1341,28 +1342,20 @@ impl<'ra> ResolverArenas<'ra> {
13411342        span :  Span , 
13421343        no_implicit_prelude :  bool , 
13431344    )  -> Module < ' ra >  { 
1344-         let  ( def_id,  self_binding)  = match  kind { 
1345-             ModuleKind :: Def ( def_kind,  def_id,  _)  => ( 
1346-                 Some ( def_id) , 
1347-                 Some ( self . new_pub_res_binding ( Res :: Def ( def_kind,  def_id) ,  span,  LocalExpnId :: ROOT ) ) , 
1348-             ) , 
1349-             ModuleKind :: Block  => ( None ,  None ) , 
1345+         let  self_binding = match  kind { 
1346+             ModuleKind :: Def ( def_kind,  def_id,  _)  => { 
1347+                 Some ( self . new_pub_res_binding ( Res :: Def ( def_kind,  def_id) ,  span,  LocalExpnId :: ROOT ) ) 
1348+             } 
1349+             ModuleKind :: Block  => None , 
13501350        } ; 
1351-         let  module =  Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new ( 
1351+         Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new ( 
13521352            parent, 
13531353            kind, 
13541354            expn_id, 
13551355            span, 
13561356            no_implicit_prelude, 
13571357            self_binding, 
1358-         ) ) ) ) ; 
1359-         if  def_id. is_none_or ( |def_id| def_id. is_local ( ) )  { 
1360-             self . local_modules . borrow_mut ( ) . push ( module) ; 
1361-         } 
1362-         module
1363-     } 
1364-     fn  local_modules ( & ' ra  self )  -> std:: cell:: Ref < ' ra ,  Vec < Module < ' ra > > >  { 
1365-         self . local_modules . borrow ( ) 
1358+         ) ) ) ) 
13661359    } 
13671360    fn  alloc_name_binding ( & ' ra  self ,  name_binding :  NameBindingData < ' ra > )  -> NameBinding < ' ra >  { 
13681361        Interned :: new_unchecked ( self . dropless . alloc ( name_binding) ) 
@@ -1505,15 +1498,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15051498        arenas :  & ' ra  ResolverArenas < ' ra > , 
15061499    )  -> Resolver < ' ra ,  ' tcx >  { 
15071500        let  root_def_id = CRATE_DEF_ID . to_def_id ( ) ; 
1508-         let  mut  local_module_map = FxIndexMap :: default ( ) ; 
15091501        let  graph_root = arenas. new_module ( 
15101502            None , 
15111503            ModuleKind :: Def ( DefKind :: Mod ,  root_def_id,  None ) , 
15121504            ExpnId :: root ( ) , 
15131505            crate_span, 
15141506            attr:: contains_name ( attrs,  sym:: no_implicit_prelude) , 
15151507        ) ; 
1516-         local_module_map. insert ( CRATE_DEF_ID ,  graph_root) ; 
1508+         let  local_modules = vec ! [ graph_root] ; 
1509+         let  local_module_map = FxIndexMap :: from_iter ( [ ( CRATE_DEF_ID ,  graph_root) ] ) ; 
15171510        let  empty_module = arenas. new_module ( 
15181511            None , 
15191512            ModuleKind :: Def ( DefKind :: Mod ,  root_def_id,  None ) , 
@@ -1591,6 +1584,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15911584            module_children :  Default :: default ( ) , 
15921585            trait_map :  NodeMap :: default ( ) , 
15931586            empty_module, 
1587+             local_modules, 
15941588            local_module_map, 
15951589            extern_module_map :  Default :: default ( ) , 
15961590            block_map :  Default :: default ( ) , 
@@ -1694,6 +1688,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16941688        no_implicit_prelude :  bool , 
16951689    )  -> Module < ' ra >  { 
16961690        let  module = self . arenas . new_module ( parent,  kind,  expn_id,  span,  no_implicit_prelude) ; 
1691+         self . local_modules . push ( module) ; 
16971692        if  let  Some ( def_id)  = module. opt_def_id ( )  { 
16981693            self . local_module_map . insert ( def_id. expect_local ( ) ,  module) ; 
16991694        } 
0 commit comments