aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/code_model.rs27
-rw-r--r--crates/hir/src/semantics/source_to_def.rs10
-rw-r--r--crates/hir_def/src/find_path.rs27
-rw-r--r--crates/hir_def/src/import_map.rs2
-rw-r--r--crates/hir_def/src/lib.rs4
-rw-r--r--crates/hir_def/src/nameres.rs4
-rw-r--r--crates/hir_def/src/nameres/collector.rs27
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs24
-rw-r--r--crates/hir_def/src/resolver.rs2
-rw-r--r--crates/hir_def/src/test_db.rs6
-rw-r--r--crates/hir_ty/src/test_db.rs2
11 files changed, 48 insertions, 87 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index d9b4cdfce..e9bb4f541 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -18,8 +18,8 @@ use hir_def::{
18 type_ref::{Mutability, TypeRef}, 18 type_ref::{Mutability, TypeRef},
19 AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, 19 AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId,
20 DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId, 20 DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId,
21 LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId, TraitId, 21 LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
22 TypeAliasId, TypeParamId, UnionId, 22 TypeParamId, UnionId,
23}; 23};
24use hir_def::{find_path::PrefixKind, item_scope::ItemInNs, visibility::Visibility}; 24use hir_def::{find_path::PrefixKind, item_scope::ItemInNs, visibility::Visibility};
25use hir_expand::{ 25use hir_expand::{
@@ -90,8 +90,8 @@ impl Crate {
90 } 90 }
91 91
92 pub fn root_module(self, db: &dyn HirDatabase) -> Module { 92 pub fn root_module(self, db: &dyn HirDatabase) -> Module {
93 let module_id = db.crate_def_map(self.id).root(); 93 let def_map = db.crate_def_map(self.id);
94 Module::new(self, module_id) 94 Module { id: def_map.module_id(def_map.root()) }
95 } 95 }
96 96
97 pub fn root_file(self, db: &dyn HirDatabase) -> FileId { 97 pub fn root_file(self, db: &dyn HirDatabase) -> FileId {
@@ -275,10 +275,6 @@ impl ModuleDef {
275} 275}
276 276
277impl Module { 277impl Module {
278 pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module {
279 Module { id: ModuleId::top_level(krate.id, crate_module_id) }
280 }
281
282 /// Name of this module. 278 /// Name of this module.
283 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 279 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
284 let def_map = self.id.def_map(db.upcast()); 280 let def_map = self.id.def_map(db.upcast());
@@ -302,7 +298,7 @@ impl Module {
302 /// in the module tree of any target in `Cargo.toml`. 298 /// in the module tree of any target in `Cargo.toml`.
303 pub fn crate_root(self, db: &dyn HirDatabase) -> Module { 299 pub fn crate_root(self, db: &dyn HirDatabase) -> Module {
304 let def_map = db.crate_def_map(self.id.krate()); 300 let def_map = db.crate_def_map(self.id.krate());
305 self.with_module_id(def_map.root()) 301 Module { id: def_map.module_id(def_map.root()) }
306 } 302 }
307 303
308 /// Iterates over all child modules. 304 /// Iterates over all child modules.
@@ -311,7 +307,7 @@ impl Module {
311 let children = def_map[self.id.local_id] 307 let children = def_map[self.id.local_id]
312 .children 308 .children
313 .iter() 309 .iter()
314 .map(|(_, module_id)| self.with_module_id(*module_id)) 310 .map(|(_, module_id)| Module { id: def_map.module_id(*module_id) })
315 .collect::<Vec<_>>(); 311 .collect::<Vec<_>>();
316 children.into_iter() 312 children.into_iter()
317 } 313 }
@@ -321,7 +317,7 @@ impl Module {
321 // FIXME: handle block expressions as modules (their parent is in a different DefMap) 317 // FIXME: handle block expressions as modules (their parent is in a different DefMap)
322 let def_map = self.id.def_map(db.upcast()); 318 let def_map = self.id.def_map(db.upcast());
323 let parent_id = def_map[self.id.local_id].parent?; 319 let parent_id = def_map[self.id.local_id].parent?;
324 Some(self.with_module_id(parent_id)) 320 Some(Module { id: def_map.module_id(parent_id) })
325 } 321 }
326 322
327 pub fn path_to_root(self, db: &dyn HirDatabase) -> Vec<Module> { 323 pub fn path_to_root(self, db: &dyn HirDatabase) -> Vec<Module> {
@@ -406,10 +402,6 @@ impl Module {
406 def_map[self.id.local_id].scope.impls().map(Impl::from).collect() 402 def_map[self.id.local_id].scope.impls().map(Impl::from).collect()
407 } 403 }
408 404
409 pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module {
410 Module::new(self.krate(), module_id)
411 }
412
413 /// Finds a path that can be used to refer to the given item from within 405 /// Finds a path that can be used to refer to the given item from within
414 /// this module, if possible. 406 /// this module, if possible.
415 pub fn find_use_path(self, db: &dyn DefDatabase, item: impl Into<ItemInNs>) -> Option<ModPath> { 407 pub fn find_use_path(self, db: &dyn DefDatabase, item: impl Into<ItemInNs>) -> Option<ModPath> {
@@ -1013,8 +1005,9 @@ impl MacroDef {
1013 /// early, in `hir_expand`, where modules simply do not exist yet. 1005 /// early, in `hir_expand`, where modules simply do not exist yet.
1014 pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { 1006 pub fn module(self, db: &dyn HirDatabase) -> Option<Module> {
1015 let krate = self.id.krate; 1007 let krate = self.id.krate;
1016 let module_id = db.crate_def_map(krate).root(); 1008 let def_map = db.crate_def_map(krate);
1017 Some(Module::new(Crate { id: krate }, module_id)) 1009 let module_id = def_map.root();
1010 Some(Module { id: def_map.module_id(module_id) })
1018 } 1011 }
1019 1012
1020 /// XXX: this parses the file 1013 /// XXX: this parses the file
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs
index faede3269..6c612ee86 100644
--- a/crates/hir/src/semantics/source_to_def.rs
+++ b/crates/hir/src/semantics/source_to_def.rs
@@ -30,13 +30,12 @@ pub(super) struct SourceToDefCtx<'a, 'b> {
30impl SourceToDefCtx<'_, '_> { 30impl SourceToDefCtx<'_, '_> {
31 pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { 31 pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> {
32 let _p = profile::span("SourceBinder::to_module_def"); 32 let _p = profile::span("SourceBinder::to_module_def");
33 let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { 33 self.db.relevant_crates(file).iter().find_map(|&crate_id| {
34 // FIXME: inner items 34 // FIXME: inner items
35 let crate_def_map = self.db.crate_def_map(crate_id); 35 let crate_def_map = self.db.crate_def_map(crate_id);
36 let local_id = crate_def_map.modules_for_file(file).next()?; 36 let local_id = crate_def_map.modules_for_file(file).next()?;
37 Some((crate_id, local_id)) 37 Some(crate_def_map.module_id(local_id))
38 })?; 38 })
39 Some(ModuleId::top_level(krate, local_id))
40 } 39 }
41 40
42 pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { 41 pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
@@ -63,8 +62,7 @@ impl SourceToDefCtx<'_, '_> {
63 let child_name = src.value.name()?.as_name(); 62 let child_name = src.value.name()?.as_name();
64 let def_map = parent_module.def_map(self.db.upcast()); 63 let def_map = parent_module.def_map(self.db.upcast());
65 let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; 64 let child_id = *def_map[parent_module.local_id].children.get(&child_name)?;
66 // FIXME: handle block expression modules 65 Some(def_map.module_id(child_id))
67 Some(ModuleId::top_level(parent_module.krate(), child_id))
68 } 66 }
69 67
70 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { 68 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index c01b6daf2..94a1d567d 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -53,12 +53,8 @@ fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option<
53 Some(ModPath::from_segments(PathKind::Super(0), Vec::new())) 53 Some(ModPath::from_segments(PathKind::Super(0), Vec::new()))
54 } else if let Some(parent_id) = def_map[from.local_id].parent { 54 } else if let Some(parent_id) = def_map[from.local_id].parent {
55 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly) 55 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
56 if item 56 let parent_id = def_map.module_id(parent_id);
57 == ItemInNs::Types(ModuleDefId::ModuleId(ModuleId { 57 if item == ItemInNs::Types(ModuleDefId::ModuleId(parent_id)) {
58 krate: from.krate,
59 local_id: parent_id,
60 }))
61 {
62 Some(ModPath::from_segments(PathKind::Super(1), Vec::new())) 58 Some(ModPath::from_segments(PathKind::Super(1), Vec::new()))
63 } else { 59 } else {
64 None 60 None
@@ -120,12 +116,8 @@ fn find_path_inner(
120 } 116 }
121 117
122 // - if the item is the crate root, return `crate` 118 // - if the item is the crate root, return `crate`
123 if item 119 let root = def_map.module_id(def_map.root());
124 == ItemInNs::Types(ModuleDefId::ModuleId(ModuleId { 120 if item == ItemInNs::Types(ModuleDefId::ModuleId(root)) {
125 krate: from.krate,
126 local_id: def_map.root(),
127 }))
128 {
129 return Some(ModPath::from_segments(PathKind::Crate, Vec::new())); 121 return Some(ModPath::from_segments(PathKind::Crate, Vec::new()));
130 } 122 }
131 123
@@ -175,7 +167,7 @@ fn find_path_inner(
175 167
176 // - otherwise, look for modules containing (reexporting) it and import it from one of those 168 // - otherwise, look for modules containing (reexporting) it and import it from one of those
177 169
178 let crate_root = ModuleId { local_id: def_map.root(), krate: from.krate }; 170 let crate_root = def_map.module_id(def_map.root());
179 let crate_attrs = db.attrs(crate_root.into()); 171 let crate_attrs = db.attrs(crate_root.into());
180 let prefer_no_std = crate_attrs.by_key("no_std").exists(); 172 let prefer_no_std = crate_attrs.by_key("no_std").exists();
181 let mut best_path = None; 173 let mut best_path = None;
@@ -288,14 +280,11 @@ fn find_local_import_locations(
288 // Compute the initial worklist. We start with all direct child modules of `from` as well as all 280 // Compute the initial worklist. We start with all direct child modules of `from` as well as all
289 // of its (recursive) parent modules. 281 // of its (recursive) parent modules.
290 let data = &def_map[from.local_id]; 282 let data = &def_map[from.local_id];
291 let mut worklist = data 283 let mut worklist =
292 .children 284 data.children.values().map(|child| def_map.module_id(*child)).collect::<Vec<_>>();
293 .values()
294 .map(|child| ModuleId { krate: from.krate, local_id: *child })
295 .collect::<Vec<_>>();
296 let mut parent = data.parent; 285 let mut parent = data.parent;
297 while let Some(p) = parent { 286 while let Some(p) = parent {
298 worklist.push(ModuleId { krate: from.krate, local_id: p }); 287 worklist.push(def_map.module_id(p));
299 parent = def_map[p].parent; 288 parent = def_map[p].parent;
300 } 289 }
301 290
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index 0b7830445..0a3dc7956 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -75,7 +75,7 @@ impl ImportMap {
75 75
76 // We look only into modules that are public(ly reexported), starting with the crate root. 76 // We look only into modules that are public(ly reexported), starting with the crate root.
77 let empty = ImportPath { segments: vec![] }; 77 let empty = ImportPath { segments: vec![] };
78 let root = ModuleId { krate, local_id: def_map.root() }; 78 let root = def_map.module_id(def_map.root());
79 let mut worklist = vec![(root, empty)]; 79 let mut worklist = vec![(root, empty)];
80 while let Some((module, mod_path)) = worklist.pop() { 80 while let Some((module, mod_path)) = worklist.pop() {
81 let ext_def_map; 81 let ext_def_map;
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index c8dbb2aeb..cf09ebd3f 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -78,10 +78,6 @@ pub struct ModuleId {
78} 78}
79 79
80impl ModuleId { 80impl ModuleId {
81 pub fn top_level(krate: CrateId, local_id: LocalModuleId) -> Self {
82 Self { krate, local_id }
83 }
84
85 pub fn def_map(&self, db: &dyn db::DefDatabase) -> Arc<DefMap> { 81 pub fn def_map(&self, db: &dyn db::DefDatabase) -> Arc<DefMap> {
86 db.crate_def_map(self.krate) 82 db.crate_def_map(self.krate)
87 } 83 }
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index bd3ea9b8b..4fbbecb38 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -265,6 +265,10 @@ impl DefMap {
265 self.extern_prelude.iter() 265 self.extern_prelude.iter()
266 } 266 }
267 267
268 pub fn module_id(&self, local_id: LocalModuleId) -> ModuleId {
269 ModuleId { krate: self.krate, local_id }
270 }
271
268 pub(crate) fn resolve_path( 272 pub(crate) fn resolve_path(
269 &self, 273 &self,
270 db: &dyn DefDatabase, 274 db: &dyn DefDatabase,
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index adfcf879a..393170b32 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -37,8 +37,8 @@ use crate::{
37 per_ns::PerNs, 37 per_ns::PerNs,
38 visibility::{RawVisibility, Visibility}, 38 visibility::{RawVisibility, Visibility},
39 AdtId, AsMacroCall, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, 39 AdtId, AsMacroCall, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId,
40 FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, 40 FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc,
41 TraitLoc, TypeAliasLoc, UnionLoc, 41 TypeAliasLoc, UnionLoc,
42}; 42};
43 43
44const GLOB_RECURSION_LIMIT: usize = 100; 44const GLOB_RECURSION_LIMIT: usize = 100;
@@ -56,10 +56,9 @@ pub(super) fn collect_defs(
56 for dep in &crate_graph[def_map.krate].dependencies { 56 for dep in &crate_graph[def_map.krate].dependencies {
57 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); 57 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
58 let dep_def_map = db.crate_def_map(dep.crate_id); 58 let dep_def_map = db.crate_def_map(dep.crate_id);
59 def_map.extern_prelude.insert( 59 def_map
60 dep.as_name(), 60 .extern_prelude
61 ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), 61 .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into());
62 );
63 62
64 // look for the prelude 63 // look for the prelude
65 // If the dependency defines a prelude, we overwrite an already defined 64 // If the dependency defines a prelude, we overwrite an already defined
@@ -332,11 +331,9 @@ impl DefCollector<'_> {
332 // exported in type/value namespace. This function reduces the visibility of all items 331 // exported in type/value namespace. This function reduces the visibility of all items
333 // in the crate root that aren't proc macros. 332 // in the crate root that aren't proc macros.
334 let root = self.def_map.root; 333 let root = self.def_map.root;
334 let module_id = self.def_map.module_id(root);
335 let root = &mut self.def_map.modules[root]; 335 let root = &mut self.def_map.modules[root];
336 root.scope.censor_non_proc_macros(ModuleId { 336 root.scope.censor_non_proc_macros(module_id);
337 krate: self.def_map.krate,
338 local_id: self.def_map.root,
339 });
340 } 337 }
341 } 338 }
342 339
@@ -1029,8 +1026,7 @@ impl ModCollector<'_, '_> {
1029 continue; 1026 continue;
1030 } 1027 }
1031 } 1028 }
1032 let module = 1029 let module = self.def_collector.def_map.module_id(self.module_id);
1033 ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
1034 let container = ContainerId::ModuleId(module); 1030 let container = ContainerId::ModuleId(module);
1035 1031
1036 let mut def = None; 1032 let mut def = None;
@@ -1097,10 +1093,7 @@ impl ModCollector<'_, '_> {
1097 } 1093 }
1098 } 1094 }
1099 ModItem::Impl(imp) => { 1095 ModItem::Impl(imp) => {
1100 let module = ModuleId { 1096 let module = self.def_collector.def_map.module_id(self.module_id);
1101 krate: self.def_collector.def_map.krate,
1102 local_id: self.module_id,
1103 };
1104 let container = ContainerId::ModuleId(module); 1097 let container = ContainerId::ModuleId(module);
1105 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } 1098 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) }
1106 .intern(self.def_collector.db); 1099 .intern(self.def_collector.db);
@@ -1343,7 +1336,7 @@ impl ModCollector<'_, '_> {
1343 modules[res].scope.define_legacy_macro(name, mac) 1336 modules[res].scope.define_legacy_macro(name, mac)
1344 } 1337 }
1345 modules[self.module_id].children.insert(name.clone(), res); 1338 modules[self.module_id].children.insert(name.clone(), res);
1346 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; 1339 let module = self.def_collector.def_map.module_id(res);
1347 let def: ModuleDefId = module.into(); 1340 let def: ModuleDefId = module.into();
1348 self.def_collector.def_map.modules[self.module_id].scope.define_def(def); 1341 self.def_collector.def_map.modules[self.module_id].scope.define_def(def);
1349 self.def_collector.update( 1342 self.def_collector.update(
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 7b5fe24a7..c1eded5f2 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -24,7 +24,7 @@ use crate::{
24 path::{ModPath, PathKind}, 24 path::{ModPath, PathKind},
25 per_ns::PerNs, 25 per_ns::PerNs,
26 visibility::{RawVisibility, Visibility}, 26 visibility::{RawVisibility, Visibility},
27 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 27 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId,
28}; 28};
29 29
30#[derive(Debug, Clone, Copy, PartialEq, Eq)] 30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -66,10 +66,7 @@ impl DefMap {
66 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { 66 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
67 if name == &name!(self) { 67 if name == &name!(self) {
68 mark::hit!(extern_crate_self_as); 68 mark::hit!(extern_crate_self_as);
69 return PerNs::types( 69 return PerNs::types(self.module_id(self.root).into(), Visibility::Public);
70 ModuleId { krate: self.krate, local_id: self.root }.into(),
71 Visibility::Public,
72 );
73 } 70 }
74 self.extern_prelude 71 self.extern_prelude
75 .get(name) 72 .get(name)
@@ -154,21 +151,15 @@ impl DefMap {
154 PathKind::DollarCrate(krate) => { 151 PathKind::DollarCrate(krate) => {
155 if krate == self.krate { 152 if krate == self.krate {
156 mark::hit!(macro_dollar_crate_self); 153 mark::hit!(macro_dollar_crate_self);
157 PerNs::types( 154 PerNs::types(self.module_id(self.root).into(), Visibility::Public)
158 ModuleId { krate: self.krate, local_id: self.root }.into(),
159 Visibility::Public,
160 )
161 } else { 155 } else {
162 let def_map = db.crate_def_map(krate); 156 let def_map = db.crate_def_map(krate);
163 let module = ModuleId { krate, local_id: def_map.root }; 157 let module = def_map.module_id(def_map.root);
164 mark::hit!(macro_dollar_crate_other); 158 mark::hit!(macro_dollar_crate_other);
165 PerNs::types(module.into(), Visibility::Public) 159 PerNs::types(module.into(), Visibility::Public)
166 } 160 }
167 } 161 }
168 PathKind::Crate => PerNs::types( 162 PathKind::Crate => PerNs::types(self.module_id(self.root).into(), Visibility::Public),
169 ModuleId { krate: self.krate, local_id: self.root }.into(),
170 Visibility::Public,
171 ),
172 // plain import or absolute path in 2015: crate-relative with 163 // plain import or absolute path in 2015: crate-relative with
173 // fallback to extern prelude (with the simplification in 164 // fallback to extern prelude (with the simplification in
174 // rust-lang/rust#57745) 165 // rust-lang/rust#57745)
@@ -205,10 +196,7 @@ impl DefMap {
205 let m = successors(Some(original_module), |m| self.modules[*m].parent) 196 let m = successors(Some(original_module), |m| self.modules[*m].parent)
206 .nth(lvl as usize); 197 .nth(lvl as usize);
207 if let Some(local_id) = m { 198 if let Some(local_id) = m {
208 PerNs::types( 199 PerNs::types(self.module_id(local_id).into(), Visibility::Public)
209 ModuleId { krate: self.krate, local_id }.into(),
210 Visibility::Public,
211 )
212 } else { 200 } else {
213 log::debug!("super path in root module"); 201 log::debug!("super path in root module");
214 return ResolvePathResult::empty(ReachedFixedPoint::Yes); 202 return ResolvePathResult::empty(ReachedFixedPoint::Yes);
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index 130c074f0..9021ea712 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -459,7 +459,7 @@ impl Resolver {
459 459
460 pub fn module(&self) -> Option<ModuleId> { 460 pub fn module(&self) -> Option<ModuleId> {
461 let (def_map, local_id) = self.module_scope()?; 461 let (def_map, local_id) = self.module_scope()?;
462 Some(ModuleId { krate: def_map.krate(), local_id }) 462 Some(def_map.module_id(local_id))
463 } 463 }
464 464
465 pub fn krate(&self) -> Option<CrateId> { 465 pub fn krate(&self) -> Option<CrateId> {
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs
index 4ff219fb7..c4e36eda5 100644
--- a/crates/hir_def/src/test_db.rs
+++ b/crates/hir_def/src/test_db.rs
@@ -15,7 +15,7 @@ use rustc_hash::FxHashSet;
15use syntax::{TextRange, TextSize}; 15use syntax::{TextRange, TextSize};
16use test_utils::extract_annotations; 16use test_utils::extract_annotations;
17 17
18use crate::{db::DefDatabase, ModuleDefId}; 18use crate::{db::DefDatabase, ModuleDefId, ModuleId};
19 19
20#[salsa::database( 20#[salsa::database(
21 base_db::SourceDatabaseExtStorage, 21 base_db::SourceDatabaseExtStorage,
@@ -72,12 +72,12 @@ impl FileLoader for TestDB {
72} 72}
73 73
74impl TestDB { 74impl TestDB {
75 pub(crate) fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { 75 pub(crate) fn module_for_file(&self, file_id: FileId) -> ModuleId {
76 for &krate in self.relevant_crates(file_id).iter() { 76 for &krate in self.relevant_crates(file_id).iter() {
77 let crate_def_map = self.crate_def_map(krate); 77 let crate_def_map = self.crate_def_map(krate);
78 for (local_id, data) in crate_def_map.modules() { 78 for (local_id, data) in crate_def_map.modules() {
79 if data.origin.file_id() == Some(file_id) { 79 if data.origin.file_id() == Some(file_id) {
80 return crate::ModuleId { krate, local_id }; 80 return crate_def_map.module_id(local_id);
81 } 81 }
82 } 82 }
83 } 83 }
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs
index 09696fcf4..381b98ba8 100644
--- a/crates/hir_ty/src/test_db.rs
+++ b/crates/hir_ty/src/test_db.rs
@@ -83,7 +83,7 @@ impl TestDB {
83 let crate_def_map = self.crate_def_map(krate); 83 let crate_def_map = self.crate_def_map(krate);
84 for (local_id, data) in crate_def_map.modules() { 84 for (local_id, data) in crate_def_map.modules() {
85 if data.origin.file_id() == Some(file_id) { 85 if data.origin.file_id() == Some(file_id) {
86 return ModuleId::top_level(krate, local_id); 86 return crate_def_map.module_id(local_id);
87 } 87 }
88 } 88 }
89 } 89 }