@@ -827,22 +827,6 @@ pub struct ModuleS<'a> {
827
827
resolutions : RefCell < HashMap < ( Name , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ,
828
828
unresolved_imports : RefCell < Vec < & ' a ImportDirective < ' a > > > ,
829
829
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
-
846
830
prelude : RefCell < Option < Module < ' a > > > ,
847
831
848
832
glob_importers : RefCell < Vec < ( Module < ' a > , & ' a ImportDirective < ' a > ) > > ,
@@ -871,7 +855,6 @@ impl<'a> ModuleS<'a> {
871
855
extern_crate_id : None ,
872
856
resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
873
857
unresolved_imports : RefCell :: new ( Vec :: new ( ) ) ,
874
- module_children : RefCell :: new ( NodeMap ( ) ) ,
875
858
prelude : RefCell :: new ( None ) ,
876
859
glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
877
860
globs : RefCell :: new ( ( Vec :: new ( ) ) ) ,
@@ -1078,6 +1061,22 @@ pub struct Resolver<'a, 'tcx: 'a> {
1078
1061
export_map : ExportMap ,
1079
1062
trait_map : TraitMap ,
1080
1063
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
+
1081
1080
// Whether or not to print error messages. Can be set to true
1082
1081
// when getting additional info for error message suggestions,
1083
1082
// so as to avoid printing duplicate errors
@@ -1179,6 +1178,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1179
1178
freevars_seen : NodeMap ( ) ,
1180
1179
export_map : NodeMap ( ) ,
1181
1180
trait_map : NodeMap ( ) ,
1181
+ module_map : NodeMap ( ) ,
1182
1182
used_imports : HashSet :: new ( ) ,
1183
1183
used_crates : HashSet :: new ( ) ,
1184
1184
@@ -1578,7 +1578,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1578
1578
fn with_scope < F > ( & mut self , id : NodeId , f : F )
1579
1579
where F : FnOnce ( & mut Resolver )
1580
1580
{
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 {
1582
1583
// Move down in the graph.
1583
1584
let orig_module = :: std:: mem:: replace ( & mut self . current_module , module) ;
1584
1585
self . value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
@@ -2129,8 +2130,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2129
2130
debug ! ( "(resolving block) entering block" ) ;
2130
2131
// Move down in the graph, if there's an anonymous module rooted here.
2131
2132
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
2134
2134
2135
2135
if let Some ( anonymous_module) = anonymous_module {
2136
2136
debug ! ( "(resolving block) found anonymous module, moving down" ) ;
0 commit comments