Skip to content

Commit

Permalink
Add comments to Resolve::get_module
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Jun 6, 2020
1 parent 47c3158 commit ff327c8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,30 @@ impl<'a> Resolver<'a> {
}

crate fn get_module(&mut self, def_id: DefId) -> Module<'a> {
// If this is a local module, it will be in `module_map`, no need to recalculate it.
if let Some(def_id) = def_id.as_local() {
return self.module_map[&def_id];
}

// Cache module resolution
if let Some(&module) = self.extern_module_map.get(&def_id) {
return module;
}

let (name, parent) = if def_id.index == CRATE_DEF_INDEX {
// This is the crate root
(self.cstore().crate_name_untracked(def_id.krate), None)
} else {
let def_key = self.cstore().def_key(def_id);
(
// This unwrap is safe: crates must always have a name
def_key.disambiguated_data.data.get_opt_name().unwrap(),
// This unwrap is safe since we know this isn't the root
Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id })),
)
};

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

0 comments on commit ff327c8

Please sign in to comment.