]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_resolve/build_reduced_graph.rs
Add comments to `Resolve::get_module`
[rust.git] / src / librustc_resolve / build_reduced_graph.rs
index 9ee3d989bf3f1e1275290c48cd7efde613672800..2ae063660e38d9d9ba178fc5630cea14a56a8182 100644 (file)
@@ -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,