@@ -827,22 +827,6 @@ pub struct ModuleS<'a> {
827827 resolutions : RefCell < HashMap < ( Name , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ,
828828 unresolved_imports : RefCell < Vec < & ' a ImportDirective < ' a > > > ,
829829
830- // The module children of this node, including normal modules and anonymous modules.
831- // Anonymous children are pseudo-modules that are implicitly created around items
832- // contained within blocks.
833- //
834- // For example, if we have this:
835- //
836- // fn f() {
837- // fn g() {
838- // ...
839- // }
840- // }
841- //
842- // There will be an anonymous module created around `g` with the ID of the
843- // entry block for `f`.
844- module_children : RefCell < NodeMap < Module < ' a > > > ,
845-
846830 prelude : RefCell < Option < Module < ' a > > > ,
847831
848832 glob_importers : RefCell < Vec < ( Module < ' a > , & ' a ImportDirective < ' a > ) > > ,
@@ -871,7 +855,6 @@ impl<'a> ModuleS<'a> {
871855 extern_crate_id : None ,
872856 resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
873857 unresolved_imports : RefCell :: new ( Vec :: new ( ) ) ,
874- module_children : RefCell :: new ( NodeMap ( ) ) ,
875858 prelude : RefCell :: new ( None ) ,
876859 glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
877860 globs : RefCell :: new ( ( Vec :: new ( ) ) ) ,
@@ -1078,6 +1061,22 @@ pub struct Resolver<'a, 'tcx: 'a> {
10781061 export_map : ExportMap ,
10791062 trait_map : TraitMap ,
10801063
1064+ // A map from nodes to modules, both normal (`mod`) modules and anonymous modules.
1065+ // Anonymous modules are pseudo-modules that are implicitly created around items
1066+ // contained within blocks.
1067+ //
1068+ // For example, if we have this:
1069+ //
1070+ // fn f() {
1071+ // fn g() {
1072+ // ...
1073+ // }
1074+ // }
1075+ //
1076+ // There will be an anonymous module created around `g` with the ID of the
1077+ // entry block for `f`.
1078+ module_map : NodeMap < Module < ' a > > ,
1079+
10811080 // Whether or not to print error messages. Can be set to true
10821081 // when getting additional info for error message suggestions,
10831082 // so as to avoid printing duplicate errors
@@ -1179,6 +1178,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11791178 freevars_seen : NodeMap ( ) ,
11801179 export_map : NodeMap ( ) ,
11811180 trait_map : NodeMap ( ) ,
1181+ module_map : NodeMap ( ) ,
11821182 used_imports : HashSet :: new ( ) ,
11831183 used_crates : HashSet :: new ( ) ,
11841184
@@ -1578,7 +1578,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15781578 fn with_scope < F > ( & mut self , id : NodeId , f : F )
15791579 where F : FnOnce ( & mut Resolver )
15801580 {
1581- if let Some ( module) = self . current_module . module_children . borrow ( ) . get ( & id) {
1581+ let module = self . module_map . get ( & id) . cloned ( ) ; // clones a reference
1582+ if let Some ( module) = module {
15821583 // Move down in the graph.
15831584 let orig_module = :: std:: mem:: replace ( & mut self . current_module , module) ;
15841585 self . value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
@@ -2129,8 +2130,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
21292130 debug ! ( "(resolving block) entering block" ) ;
21302131 // Move down in the graph, if there's an anonymous module rooted here.
21312132 let orig_module = self . current_module ;
2132- let anonymous_module =
2133- orig_module. module_children . borrow ( ) . get ( & block. id ) . map ( |module| * module) ;
2133+ let anonymous_module = self . module_map . get ( & block. id ) . cloned ( ) ; // clones a reference
21342134
21352135 if let Some ( anonymous_module) = anonymous_module {
21362136 debug ! ( "(resolving block) found anonymous module, moving down" ) ;
0 commit comments