Skip to content

Commit 13f2838

Browse files
authored
Rollup merge of #73075 - jyn514:comment-module, r=Dylan-DPC
Add comments to `Resolve::get_module` r? @Manishearth
2 parents 244465d + ff327c8 commit 13f2838

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/librustc_resolve/build_reduced_graph.rs

+6
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,30 @@ impl<'a> Resolver<'a> {
9595
}
9696

9797
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.
9899
if let Some(def_id) = def_id.as_local() {
99100
return self.module_map[&def_id];
100101
}
101102

103+
// Cache module resolution
102104
if let Some(&module) = self.extern_module_map.get(&def_id) {
103105
return module;
104106
}
105107

106108
let (name, parent) = if def_id.index == CRATE_DEF_INDEX {
109+
// This is the crate root
107110
(self.cstore().crate_name_untracked(def_id.krate), None)
108111
} else {
109112
let def_key = self.cstore().def_key(def_id);
110113
(
114+
// This unwrap is safe: crates must always have a name
111115
def_key.disambiguated_data.data.get_opt_name().unwrap(),
116+
// This unwrap is safe since we know this isn't the root
112117
Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id })),
113118
)
114119
};
115120

121+
// Allocate and return a new module with the information we found
116122
let kind = ModuleKind::Def(DefKind::Mod, def_id, name);
117123
let module = self.arenas.alloc_module(ModuleData::new(
118124
parent,

0 commit comments

Comments
 (0)