File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -95,24 +95,30 @@ impl<'a> Resolver<'a> {
95
95
}
96
96
97
97
crate fn get_module ( & mut self , def_id : DefId ) -> Module < ' a > {
98
+ // If this is a local module, it will be in `module_map`, no need to recalculate it.
98
99
if let Some ( def_id) = def_id. as_local ( ) {
99
100
return self . module_map [ & def_id] ;
100
101
}
101
102
103
+ // Cache module resolution
102
104
if let Some ( & module) = self . extern_module_map . get ( & def_id) {
103
105
return module;
104
106
}
105
107
106
108
let ( name, parent) = if def_id. index == CRATE_DEF_INDEX {
109
+ // This is the crate root
107
110
( self . cstore ( ) . crate_name_untracked ( def_id. krate ) , None )
108
111
} else {
109
112
let def_key = self . cstore ( ) . def_key ( def_id) ;
110
113
(
114
+ // This unwrap is safe: crates must always have a name
111
115
def_key. disambiguated_data . data . get_opt_name ( ) . unwrap ( ) ,
116
+ // This unwrap is safe since we know this isn't the root
112
117
Some ( self . get_module ( DefId { index : def_key. parent . unwrap ( ) , ..def_id } ) ) ,
113
118
)
114
119
} ;
115
120
121
+ // Allocate and return a new module with the information we found
116
122
let kind = ModuleKind :: Def ( DefKind :: Mod , def_id, name) ;
117
123
let module = self . arenas . alloc_module ( ModuleData :: new (
118
124
parent,
You can’t perform that action at this time.
0 commit comments