diff options
author | Aleksey Kladov <[email protected]> | 2019-11-27 18:31:51 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-27 18:31:51 +0000 |
commit | d9a36a736bfb91578a36505e7237212959bb55fe (patch) | |
tree | d7e6ee1b610929f8e7387ef65050470a84f9d854 | |
parent | 47ec2ceb12df756b3482ddd2b1947e4b38f23706 (diff) |
Rename module_id -> local_id
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/docs.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lang_item.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 10 |
13 files changed, 47 insertions, 47 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 87c78d98e..5a3e24e9e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -174,15 +174,15 @@ pub use hir_def::attr::Attrs; | |||
174 | 174 | ||
175 | impl Module { | 175 | impl Module { |
176 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { | 176 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { |
177 | Module { id: ModuleId { krate: krate.crate_id, module_id: crate_module_id } } | 177 | Module { id: ModuleId { krate: krate.crate_id, local_id: crate_module_id } } |
178 | } | 178 | } |
179 | 179 | ||
180 | /// Name of this module. | 180 | /// Name of this module. |
181 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 181 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { |
182 | let def_map = db.crate_def_map(self.id.krate); | 182 | let def_map = db.crate_def_map(self.id.krate); |
183 | let parent = def_map[self.id.module_id].parent?; | 183 | let parent = def_map[self.id.local_id].parent?; |
184 | def_map[parent].children.iter().find_map(|(name, module_id)| { | 184 | def_map[parent].children.iter().find_map(|(name, module_id)| { |
185 | if *module_id == self.id.module_id { | 185 | if *module_id == self.id.local_id { |
186 | Some(name.clone()) | 186 | Some(name.clone()) |
187 | } else { | 187 | } else { |
188 | None | 188 | None |
@@ -206,14 +206,14 @@ impl Module { | |||
206 | /// Finds a child module with the specified name. | 206 | /// Finds a child module with the specified name. |
207 | pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> { | 207 | pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> { |
208 | let def_map = db.crate_def_map(self.id.krate); | 208 | let def_map = db.crate_def_map(self.id.krate); |
209 | let child_id = def_map[self.id.module_id].children.get(name)?; | 209 | let child_id = def_map[self.id.local_id].children.get(name)?; |
210 | Some(self.with_module_id(*child_id)) | 210 | Some(self.with_module_id(*child_id)) |
211 | } | 211 | } |
212 | 212 | ||
213 | /// Iterates over all child modules. | 213 | /// Iterates over all child modules. |
214 | pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { | 214 | pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { |
215 | let def_map = db.crate_def_map(self.id.krate); | 215 | let def_map = db.crate_def_map(self.id.krate); |
216 | let children = def_map[self.id.module_id] | 216 | let children = def_map[self.id.local_id] |
217 | .children | 217 | .children |
218 | .iter() | 218 | .iter() |
219 | .map(|(_, module_id)| self.with_module_id(*module_id)) | 219 | .map(|(_, module_id)| self.with_module_id(*module_id)) |
@@ -224,7 +224,7 @@ impl Module { | |||
224 | /// Finds a parent module. | 224 | /// Finds a parent module. |
225 | pub fn parent(self, db: &impl DefDatabase) -> Option<Module> { | 225 | pub fn parent(self, db: &impl DefDatabase) -> Option<Module> { |
226 | let def_map = db.crate_def_map(self.id.krate); | 226 | let def_map = db.crate_def_map(self.id.krate); |
227 | let parent_id = def_map[self.id.module_id].parent?; | 227 | let parent_id = def_map[self.id.local_id].parent?; |
228 | Some(self.with_module_id(parent_id)) | 228 | Some(self.with_module_id(parent_id)) |
229 | } | 229 | } |
230 | 230 | ||
@@ -240,7 +240,7 @@ impl Module { | |||
240 | 240 | ||
241 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 241 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
242 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { | 242 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { |
243 | db.crate_def_map(self.id.krate)[self.id.module_id] | 243 | db.crate_def_map(self.id.krate)[self.id.local_id] |
244 | .scope | 244 | .scope |
245 | .entries() | 245 | .entries() |
246 | .map(|(name, res)| { | 246 | .map(|(name, res)| { |
@@ -250,7 +250,7 @@ impl Module { | |||
250 | } | 250 | } |
251 | 251 | ||
252 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { | 252 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
253 | db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.module_id, sink); | 253 | db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink); |
254 | for decl in self.declarations(db) { | 254 | for decl in self.declarations(db) { |
255 | match decl { | 255 | match decl { |
256 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), | 256 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), |
@@ -275,12 +275,12 @@ impl Module { | |||
275 | 275 | ||
276 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { | 276 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { |
277 | let def_map = db.crate_def_map(self.id.krate); | 277 | let def_map = db.crate_def_map(self.id.krate); |
278 | def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect() | 278 | def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect() |
279 | } | 279 | } |
280 | 280 | ||
281 | pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { | 281 | pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { |
282 | let def_map = db.crate_def_map(self.id.krate); | 282 | let def_map = db.crate_def_map(self.id.krate); |
283 | def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect() | 283 | def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect() |
284 | } | 284 | } |
285 | 285 | ||
286 | fn with_module_id(self, module_id: LocalModuleId) -> Module { | 286 | fn with_module_id(self, module_id: LocalModuleId) -> Module { |
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 076d86f2b..bf3ee0834 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -22,7 +22,7 @@ impl Module { | |||
22 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | 22 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. |
23 | pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> { | 23 | pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> { |
24 | let def_map = db.crate_def_map(self.id.krate); | 24 | let def_map = db.crate_def_map(self.id.krate); |
25 | let src = def_map[self.id.module_id].definition_source(db); | 25 | let src = def_map[self.id.local_id].definition_source(db); |
26 | src.map(|it| match it { | 26 | src.map(|it| match it { |
27 | Either::A(it) => ModuleSource::SourceFile(it), | 27 | Either::A(it) => ModuleSource::SourceFile(it), |
28 | Either::B(it) => ModuleSource::Module(it), | 28 | Either::B(it) => ModuleSource::Module(it), |
@@ -33,7 +33,7 @@ impl Module { | |||
33 | /// `None` for the crate root. | 33 | /// `None` for the crate root. |
34 | pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { | 34 | pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { |
35 | let def_map = db.crate_def_map(self.id.krate); | 35 | let def_map = db.crate_def_map(self.id.krate); |
36 | def_map[self.id.module_id].declaration_source(db) | 36 | def_map[self.id.local_id].declaration_source(db) |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 95db7161b..7756ca80e 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -262,13 +262,13 @@ impl Module { | |||
262 | 262 | ||
263 | let original_file = src.file_id.original_file(db); | 263 | let original_file = src.file_id.original_file(db); |
264 | 264 | ||
265 | let (krate, module_id) = | 265 | let (krate, local_id) = |
266 | db.relevant_crates(original_file).iter().find_map(|&crate_id| { | 266 | db.relevant_crates(original_file).iter().find_map(|&crate_id| { |
267 | let crate_def_map = db.crate_def_map(crate_id); | 267 | let crate_def_map = db.crate_def_map(crate_id); |
268 | let local_module_id = crate_def_map.modules_for_file(original_file).next()?; | 268 | let local_id = crate_def_map.modules_for_file(original_file).next()?; |
269 | Some((crate_id, local_module_id)) | 269 | Some((crate_id, local_id)) |
270 | })?; | 270 | })?; |
271 | Some(Module { id: ModuleId { krate, module_id } }) | 271 | Some(Module { id: ModuleId { krate, local_id } }) |
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 298608e27..fffb22201 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -35,7 +35,7 @@ impl Attrs { | |||
35 | match def { | 35 | match def { |
36 | AttrDefId::ModuleId(module) => { | 36 | AttrDefId::ModuleId(module) => { |
37 | let def_map = db.crate_def_map(module.krate); | 37 | let def_map = db.crate_def_map(module.krate); |
38 | let src = match def_map[module.module_id].declaration_source(db) { | 38 | let src = match def_map[module.local_id].declaration_source(db) { |
39 | Some(it) => it, | 39 | Some(it) => it, |
40 | None => return Attrs::default(), | 40 | None => return Attrs::default(), |
41 | }; | 41 | }; |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 78a532bdd..a57a0176d 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -82,7 +82,7 @@ impl Expander { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { | 84 | fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { |
85 | self.crate_def_map.resolve_path(db, self.module.module_id, path).0.take_macros() | 85 | self.crate_def_map.resolve_path(db, self.module.local_id, path).0.take_macros() |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs index 4749b642f..34ed9b7a5 100644 --- a/crates/ra_hir_def/src/docs.rs +++ b/crates/ra_hir_def/src/docs.rs | |||
@@ -36,7 +36,7 @@ impl Documentation { | |||
36 | match def { | 36 | match def { |
37 | AttrDefId::ModuleId(module) => { | 37 | AttrDefId::ModuleId(module) => { |
38 | let def_map = db.crate_def_map(module.krate); | 38 | let def_map = db.crate_def_map(module.krate); |
39 | let src = def_map[module.module_id].declaration_source(db)?; | 39 | let src = def_map[module.local_id].declaration_source(db)?; |
40 | docs_from_ast(&src.value) | 40 | docs_from_ast(&src.value) |
41 | } | 41 | } |
42 | AttrDefId::StructFieldId(it) => { | 42 | AttrDefId::StructFieldId(it) => { |
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index f15c23db9..f4fdbdcfc 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs | |||
@@ -41,7 +41,7 @@ impl LangItems { | |||
41 | crate_def_map | 41 | crate_def_map |
42 | .modules | 42 | .modules |
43 | .iter() | 43 | .iter() |
44 | .filter_map(|(module_id, _)| db.module_lang_items(ModuleId { krate, module_id })) | 44 | .filter_map(|(local_id, _)| db.module_lang_items(ModuleId { krate, local_id })) |
45 | .for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v)))); | 45 | .for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v)))); |
46 | 46 | ||
47 | Arc::new(lang_items) | 47 | Arc::new(lang_items) |
@@ -80,7 +80,7 @@ impl LangItems { | |||
80 | fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) { | 80 | fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) { |
81 | // Look for impl targets | 81 | // Look for impl targets |
82 | let def_map = db.crate_def_map(module.krate); | 82 | let def_map = db.crate_def_map(module.krate); |
83 | let module_data = &def_map[module.module_id]; | 83 | let module_data = &def_map[module.local_id]; |
84 | for &impl_block in module_data.impls.iter() { | 84 | for &impl_block in module_data.impls.iter() { |
85 | self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId) | 85 | self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId) |
86 | } | 86 | } |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index ddf464c60..bc5530896 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -50,7 +50,7 @@ impl_arena_id!(LocalImportId); | |||
50 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 50 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
51 | pub struct ModuleId { | 51 | pub struct ModuleId { |
52 | pub krate: CrateId, | 52 | pub krate: CrateId, |
53 | pub module_id: LocalModuleId, | 53 | pub local_id: LocalModuleId, |
54 | } | 54 | } |
55 | 55 | ||
56 | /// An ID of a module, **local** to a specific crate | 56 | /// An ID of a module, **local** to a specific crate |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index ea3abfdae..6cd14026b 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -37,7 +37,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C | |||
37 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 37 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
38 | def_map.extern_prelude.insert( | 38 | def_map.extern_prelude.insert( |
39 | dep.as_name(), | 39 | dep.as_name(), |
40 | ModuleId { krate: dep.crate_id, module_id: dep_def_map.root }.into(), | 40 | ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), |
41 | ); | 41 | ); |
42 | 42 | ||
43 | // look for the prelude | 43 | // look for the prelude |
@@ -323,7 +323,7 @@ where | |||
323 | tested_by!(glob_across_crates); | 323 | tested_by!(glob_across_crates); |
324 | // glob import from other crate => we can just import everything once | 324 | // glob import from other crate => we can just import everything once |
325 | let item_map = self.db.crate_def_map(m.krate); | 325 | let item_map = self.db.crate_def_map(m.krate); |
326 | let scope = &item_map[m.module_id].scope; | 326 | let scope = &item_map[m.local_id].scope; |
327 | 327 | ||
328 | // Module scoped macros is included | 328 | // Module scoped macros is included |
329 | let items = scope | 329 | let items = scope |
@@ -337,7 +337,7 @@ where | |||
337 | // glob import from same crate => we do an initial | 337 | // glob import from same crate => we do an initial |
338 | // import, and then need to propagate any further | 338 | // import, and then need to propagate any further |
339 | // additions | 339 | // additions |
340 | let scope = &self.def_map[m.module_id].scope; | 340 | let scope = &self.def_map[m.local_id].scope; |
341 | 341 | ||
342 | // Module scoped macros is included | 342 | // Module scoped macros is included |
343 | let items = scope | 343 | let items = scope |
@@ -349,7 +349,7 @@ where | |||
349 | self.update(module_id, Some(import_id), &items); | 349 | self.update(module_id, Some(import_id), &items); |
350 | // record the glob import in case we add further items | 350 | // record the glob import in case we add further items |
351 | self.glob_imports | 351 | self.glob_imports |
352 | .entry(m.module_id) | 352 | .entry(m.local_id) |
353 | .or_default() | 353 | .or_default() |
354 | .push((module_id, import_id)); | 354 | .push((module_id, import_id)); |
355 | } | 355 | } |
@@ -590,7 +590,7 @@ where | |||
590 | raw::RawItemKind::Impl(imp) => { | 590 | raw::RawItemKind::Impl(imp) => { |
591 | let module = ModuleId { | 591 | let module = ModuleId { |
592 | krate: self.def_collector.def_map.krate, | 592 | krate: self.def_collector.def_map.krate, |
593 | module_id: self.module_id, | 593 | local_id: self.module_id, |
594 | }; | 594 | }; |
595 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); | 595 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); |
596 | let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); | 596 | let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); |
@@ -673,7 +673,7 @@ where | |||
673 | modules[self.module_id].children.insert(name.clone(), res); | 673 | modules[self.module_id].children.insert(name.clone(), res); |
674 | let resolution = Resolution { | 674 | let resolution = Resolution { |
675 | def: PerNs::types( | 675 | def: PerNs::types( |
676 | ModuleId { krate: self.def_collector.def_map.krate, module_id: res }.into(), | 676 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), |
677 | ), | 677 | ), |
678 | import: None, | 678 | import: None, |
679 | }; | 679 | }; |
@@ -683,7 +683,7 @@ where | |||
683 | 683 | ||
684 | fn define_def(&mut self, def: &raw::DefData) { | 684 | fn define_def(&mut self, def: &raw::DefData) { |
685 | let module = | 685 | let module = |
686 | ModuleId { krate: self.def_collector.def_map.krate, module_id: self.module_id }; | 686 | ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; |
687 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); | 687 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); |
688 | 688 | ||
689 | let name = def.name.clone(); | 689 | let name = def.name.clone(); |
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 9455f22bb..b72c55bd1 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs | |||
@@ -74,19 +74,19 @@ impl CrateDefMap { | |||
74 | PathKind::DollarCrate(krate) => { | 74 | PathKind::DollarCrate(krate) => { |
75 | if krate == self.krate { | 75 | if krate == self.krate { |
76 | tested_by!(macro_dollar_crate_self); | 76 | tested_by!(macro_dollar_crate_self); |
77 | PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into()) | 77 | PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) |
78 | } else { | 78 | } else { |
79 | let def_map = db.crate_def_map(krate); | 79 | let def_map = db.crate_def_map(krate); |
80 | let module = ModuleId { krate, module_id: def_map.root }; | 80 | let module = ModuleId { krate, local_id: def_map.root }; |
81 | tested_by!(macro_dollar_crate_other); | 81 | tested_by!(macro_dollar_crate_other); |
82 | PerNs::types(module.into()) | 82 | PerNs::types(module.into()) |
83 | } | 83 | } |
84 | } | 84 | } |
85 | PathKind::Crate => { | 85 | PathKind::Crate => { |
86 | PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into()) | 86 | PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) |
87 | } | 87 | } |
88 | PathKind::Self_ => { | 88 | PathKind::Self_ => { |
89 | PerNs::types(ModuleId { krate: self.krate, module_id: original_module }.into()) | 89 | PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into()) |
90 | } | 90 | } |
91 | // plain import or absolute path in 2015: crate-relative with | 91 | // plain import or absolute path in 2015: crate-relative with |
92 | // fallback to extern prelude (with the simplification in | 92 | // fallback to extern prelude (with the simplification in |
@@ -113,7 +113,7 @@ impl CrateDefMap { | |||
113 | } | 113 | } |
114 | PathKind::Super => { | 114 | PathKind::Super => { |
115 | if let Some(p) = self.modules[original_module].parent { | 115 | if let Some(p) = self.modules[original_module].parent { |
116 | PerNs::types(ModuleId { krate: self.krate, module_id: p }.into()) | 116 | PerNs::types(ModuleId { krate: self.krate, local_id: p }.into()) |
117 | } else { | 117 | } else { |
118 | log::debug!("super path in root module"); | 118 | log::debug!("super path in root module"); |
119 | return ResolvePathResult::empty(ReachedFixedPoint::Yes); | 119 | return ResolvePathResult::empty(ReachedFixedPoint::Yes); |
@@ -160,7 +160,7 @@ impl CrateDefMap { | |||
160 | Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; | 160 | Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; |
161 | log::debug!("resolving {:?} in other crate", path); | 161 | log::debug!("resolving {:?} in other crate", path); |
162 | let defp_map = db.crate_def_map(module.krate); | 162 | let defp_map = db.crate_def_map(module.krate); |
163 | let (def, s) = defp_map.resolve_path(db, module.module_id, &path); | 163 | let (def, s) = defp_map.resolve_path(db, module.local_id, &path); |
164 | return ResolvePathResult::with( | 164 | return ResolvePathResult::with( |
165 | def, | 165 | def, |
166 | ReachedFixedPoint::Yes, | 166 | ReachedFixedPoint::Yes, |
@@ -169,7 +169,7 @@ impl CrateDefMap { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | // Since it is a qualified path here, it should not contains legacy macros | 171 | // Since it is a qualified path here, it should not contains legacy macros |
172 | match self[module.module_id].scope.get(&segment.name) { | 172 | match self[module.local_id].scope.get(&segment.name) { |
173 | Some(res) => res.def, | 173 | Some(res) => res.def, |
174 | _ => { | 174 | _ => { |
175 | log::debug!("path segment {:?} not found", segment.name); | 175 | log::debug!("path segment {:?} not found", segment.name); |
@@ -254,7 +254,7 @@ impl CrateDefMap { | |||
254 | keep = db.crate_def_map(prelude.krate); | 254 | keep = db.crate_def_map(prelude.krate); |
255 | &keep | 255 | &keep |
256 | }; | 256 | }; |
257 | def_map[prelude.module_id].scope.get(name).map_or_else(PerNs::none, |res| res.def) | 257 | def_map[prelude.local_id].scope.get(name).map_or_else(PerNs::none, |res| res.def) |
258 | } else { | 258 | } else { |
259 | PerNs::none() | 259 | PerNs::none() |
260 | } | 260 | } |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 5155365cc..0847f6dcf 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -325,7 +325,7 @@ impl Resolver { | |||
325 | if let Scope::ModuleScope(m) = scope { | 325 | if let Scope::ModuleScope(m) = scope { |
326 | if let Some(prelude) = m.crate_def_map.prelude { | 326 | if let Some(prelude) = m.crate_def_map.prelude { |
327 | let prelude_def_map = db.crate_def_map(prelude.krate); | 327 | let prelude_def_map = db.crate_def_map(prelude.krate); |
328 | traits.extend(prelude_def_map[prelude.module_id].scope.traits()); | 328 | traits.extend(prelude_def_map[prelude.local_id].scope.traits()); |
329 | } | 329 | } |
330 | traits.extend(m.crate_def_map[m.module_id].scope.traits()); | 330 | traits.extend(m.crate_def_map[m.module_id].scope.traits()); |
331 | } | 331 | } |
@@ -402,7 +402,7 @@ impl Scope { | |||
402 | }); | 402 | }); |
403 | if let Some(prelude) = m.crate_def_map.prelude { | 403 | if let Some(prelude) = m.crate_def_map.prelude { |
404 | let prelude_def_map = db.crate_def_map(prelude.krate); | 404 | let prelude_def_map = db.crate_def_map(prelude.krate); |
405 | prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| { | 405 | prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, res)| { |
406 | f(name.clone(), ScopeDef::PerNs(res.def)); | 406 | f(name.clone(), ScopeDef::PerNs(res.def)); |
407 | }); | 407 | }); |
408 | } | 408 | } |
@@ -492,7 +492,7 @@ pub trait HasResolver: Copy { | |||
492 | impl HasResolver for ModuleId { | 492 | impl HasResolver for ModuleId { |
493 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 493 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
494 | let def_map = db.crate_def_map(self.krate); | 494 | let def_map = db.crate_def_map(self.krate); |
495 | Resolver::default().push_module_scope(def_map, self.module_id) | 495 | Resolver::default().push_module_scope(def_map, self.local_id) |
496 | } | 496 | } |
497 | } | 497 | } |
498 | 498 | ||
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 874357008..1dc9793f9 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -73,9 +73,9 @@ impl TestDB { | |||
73 | pub fn module_for_file(&self, file_id: FileId) -> ModuleId { | 73 | pub fn module_for_file(&self, file_id: FileId) -> ModuleId { |
74 | for &krate in self.relevant_crates(file_id).iter() { | 74 | for &krate in self.relevant_crates(file_id).iter() { |
75 | let crate_def_map = self.crate_def_map(krate); | 75 | let crate_def_map = self.crate_def_map(krate); |
76 | for (module_id, data) in crate_def_map.modules.iter() { | 76 | for (local_id, data) in crate_def_map.modules.iter() { |
77 | if data.definition == Some(file_id) { | 77 | if data.definition == Some(file_id) { |
78 | return ModuleId { krate, module_id }; | 78 | return ModuleId { krate, local_id }; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index c1744663a..c8461b447 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -4677,7 +4677,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { | |||
4677 | 4677 | ||
4678 | let module = db.module_for_file(pos.file_id); | 4678 | let module = db.module_for_file(pos.file_id); |
4679 | let crate_def_map = db.crate_def_map(module.krate); | 4679 | let crate_def_map = db.crate_def_map(module.krate); |
4680 | for decl in crate_def_map[module.module_id].scope.declarations() { | 4680 | for decl in crate_def_map[module.local_id].scope.declarations() { |
4681 | if let ModuleDefId::FunctionId(func) = decl { | 4681 | if let ModuleDefId::FunctionId(func) = decl { |
4682 | let (_body, source_map) = db.body_with_source_map(func.into()); | 4682 | let (_body, source_map) = db.body_with_source_map(func.into()); |
4683 | if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) { | 4683 | if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) { |
@@ -4753,7 +4753,7 @@ fn infer(content: &str) -> String { | |||
4753 | let crate_def_map = db.crate_def_map(module.krate); | 4753 | let crate_def_map = db.crate_def_map(module.krate); |
4754 | 4754 | ||
4755 | let mut defs: Vec<DefWithBodyId> = Vec::new(); | 4755 | let mut defs: Vec<DefWithBodyId> = Vec::new(); |
4756 | visit_module(&db, &crate_def_map, module.module_id, &mut |it| defs.push(it)); | 4756 | visit_module(&db, &crate_def_map, module.local_id, &mut |it| defs.push(it)); |
4757 | defs.sort_by_key(|def| match def { | 4757 | defs.sort_by_key(|def| match def { |
4758 | DefWithBodyId::FunctionId(it) => { | 4758 | DefWithBodyId::FunctionId(it) => { |
4759 | it.lookup(&db).ast_id.to_node(&db).syntax().text_range().start() | 4759 | it.lookup(&db).ast_id.to_node(&db).syntax().text_range().start() |
@@ -4796,7 +4796,7 @@ fn visit_module( | |||
4796 | } | 4796 | } |
4797 | } | 4797 | } |
4798 | } | 4798 | } |
4799 | ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.module_id, cb), | 4799 | ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.local_id, cb), |
4800 | _ => (), | 4800 | _ => (), |
4801 | } | 4801 | } |
4802 | } | 4802 | } |
@@ -4844,7 +4844,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
4844 | let events = db.log_executed(|| { | 4844 | let events = db.log_executed(|| { |
4845 | let module = db.module_for_file(pos.file_id); | 4845 | let module = db.module_for_file(pos.file_id); |
4846 | let crate_def_map = db.crate_def_map(module.krate); | 4846 | let crate_def_map = db.crate_def_map(module.krate); |
4847 | visit_module(&db, &crate_def_map, module.module_id, &mut |def| { | 4847 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { |
4848 | db.infer(def); | 4848 | db.infer(def); |
4849 | }); | 4849 | }); |
4850 | }); | 4850 | }); |
@@ -4866,7 +4866,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
4866 | let events = db.log_executed(|| { | 4866 | let events = db.log_executed(|| { |
4867 | let module = db.module_for_file(pos.file_id); | 4867 | let module = db.module_for_file(pos.file_id); |
4868 | let crate_def_map = db.crate_def_map(module.krate); | 4868 | let crate_def_map = db.crate_def_map(module.krate); |
4869 | visit_module(&db, &crate_def_map, module.module_id, &mut |def| { | 4869 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { |
4870 | db.infer(def); | 4870 | db.infer(def); |
4871 | }); | 4871 | }); |
4872 | }); | 4872 | }); |