aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-24 15:05:12 +0000
committerAleksey Kladov <[email protected]>2019-11-24 15:05:12 +0000
commitf5e0a31eaf9ddd7788e6261d49f4d18e8463a719 (patch)
treefcaa2b8feb899c16a49fcf87c709327653a3ec2a
parent855a629b1436e7d3f2a9ae47d242d69d1fd7327e (diff)
Cleanup nameres
-rw-r--r--crates/ra_hir/src/code_model.rs4
-rw-r--r--crates/ra_hir_def/src/lang_item.rs5
-rw-r--r--crates/ra_hir_def/src/nameres.rs32
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs5
-rw-r--r--crates/ra_hir_def/src/resolver.rs8
5 files changed, 19 insertions, 35 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index b3e2ff1c2..9f06b147c 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -62,7 +62,7 @@ impl Crate {
62 } 62 }
63 63
64 pub fn root_module(self, db: &impl DefDatabase) -> Option<Module> { 64 pub fn root_module(self, db: &impl DefDatabase) -> Option<Module> {
65 let module_id = db.crate_def_map(self.crate_id).root(); 65 let module_id = db.crate_def_map(self.crate_id).root;
66 Some(Module::new(self, module_id)) 66 Some(Module::new(self, module_id))
67 } 67 }
68 68
@@ -195,7 +195,7 @@ impl Module {
195 /// in the module tree of any target in `Cargo.toml`. 195 /// in the module tree of any target in `Cargo.toml`.
196 pub fn crate_root(self, db: &impl DefDatabase) -> Module { 196 pub fn crate_root(self, db: &impl DefDatabase) -> Module {
197 let def_map = db.crate_def_map(self.id.krate); 197 let def_map = db.crate_def_map(self.id.krate);
198 self.with_module_id(def_map.root()) 198 self.with_module_id(def_map.root)
199 } 199 }
200 200
201 /// Finds a child module with the specified name. 201 /// Finds a child module with the specified name.
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index 3b9fb0328..f15c23db9 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -39,8 +39,9 @@ impl LangItems {
39 let crate_def_map = db.crate_def_map(krate); 39 let crate_def_map = db.crate_def_map(krate);
40 40
41 crate_def_map 41 crate_def_map
42 .modules() 42 .modules
43 .filter_map(|module_id| db.module_lang_items(ModuleId { krate, module_id })) 43 .iter()
44 .filter_map(|(module_id, _)| db.module_lang_items(ModuleId { krate, module_id }))
44 .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))));
45 46
46 Arc::new(lang_items) 47 Arc::new(lang_items)
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 5919771b0..9476fb1ad 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -80,16 +80,16 @@ use crate::{
80/// Contains all top-level defs from a macro-expanded crate 80/// Contains all top-level defs from a macro-expanded crate
81#[derive(Debug, PartialEq, Eq)] 81#[derive(Debug, PartialEq, Eq)]
82pub struct CrateDefMap { 82pub struct CrateDefMap {
83 krate: CrateId, 83 pub root: LocalModuleId,
84 edition: Edition, 84 pub(crate) krate: CrateId,
85 /// The prelude module for this crate. This either comes from an import 85 /// The prelude module for this crate. This either comes from an import
86 /// marked with the `prelude_import` attribute, or (in the normal case) from 86 /// marked with the `prelude_import` attribute, or (in the normal case) from
87 /// a dependency (`std` or `core`). 87 /// a dependency (`std` or `core`).
88 prelude: Option<ModuleId>, 88 pub(crate) prelude: Option<ModuleId>,
89 extern_prelude: FxHashMap<Name, ModuleDefId>, 89 pub(crate) extern_prelude: FxHashMap<Name, ModuleDefId>,
90 root: LocalModuleId, 90 pub(crate) modules: Arena<LocalModuleId, ModuleData>,
91 modules: Arena<LocalModuleId, ModuleData>,
92 91
92 edition: Edition,
93 diagnostics: Vec<DefDiagnostic>, 93 diagnostics: Vec<DefDiagnostic>,
94} 94}
95 95
@@ -229,22 +229,6 @@ impl CrateDefMap {
229 Arc::new(def_map) 229 Arc::new(def_map)
230 } 230 }
231 231
232 pub fn krate(&self) -> CrateId {
233 self.krate
234 }
235
236 pub fn root(&self) -> LocalModuleId {
237 self.root
238 }
239
240 pub fn prelude(&self) -> Option<ModuleId> {
241 self.prelude
242 }
243
244 pub fn extern_prelude(&self) -> &FxHashMap<Name, ModuleDefId> {
245 &self.extern_prelude
246 }
247
248 pub fn add_diagnostics( 232 pub fn add_diagnostics(
249 &self, 233 &self,
250 db: &impl DefDatabase, 234 db: &impl DefDatabase,
@@ -254,10 +238,6 @@ impl CrateDefMap {
254 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) 238 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink))
255 } 239 }
256 240
257 pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ {
258 self.modules.iter().map(|(id, _data)| id)
259 }
260
261 pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = LocalModuleId> + '_ { 241 pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = LocalModuleId> + '_ {
262 self.modules 242 self.modules
263 .iter() 243 .iter()
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index df01a20e1..41becf8df 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -1,4 +1,7 @@
1//! FIXME: write short doc here 1//! The core of the module-level name resolution algorithm.
2//!
3//! `DefCollector::collect` contains the fixed-point iteration loop which
4//! resolves imports and expands macros.
2 5
3use hir_expand::{ 6use hir_expand::{
4 builtin_macro::find_builtin_macro, 7 builtin_macro::find_builtin_macro,
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 7182b8a4d..c24a9b165 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -321,7 +321,7 @@ impl Resolver {
321 let mut traits = FxHashSet::default(); 321 let mut traits = FxHashSet::default();
322 for scope in &self.scopes { 322 for scope in &self.scopes {
323 if let Scope::ModuleScope(m) = scope { 323 if let Scope::ModuleScope(m) = scope {
324 if let Some(prelude) = m.crate_def_map.prelude() { 324 if let Some(prelude) = m.crate_def_map.prelude {
325 let prelude_def_map = db.crate_def_map(prelude.krate); 325 let prelude_def_map = db.crate_def_map(prelude.krate);
326 traits.extend(prelude_def_map[prelude.module_id].scope.traits()); 326 traits.extend(prelude_def_map[prelude.module_id].scope.traits());
327 } 327 }
@@ -340,7 +340,7 @@ impl Resolver {
340 } 340 }
341 341
342 pub fn krate(&self) -> Option<CrateId> { 342 pub fn krate(&self) -> Option<CrateId> {
343 self.module().map(|t| t.0.krate()) 343 self.module().map(|t| t.0.krate)
344 } 344 }
345 345
346 pub fn where_predicates_in_scope<'a>( 346 pub fn where_predicates_in_scope<'a>(
@@ -395,10 +395,10 @@ impl Scope {
395 m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { 395 m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| {
396 f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_))); 396 f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_)));
397 }); 397 });
398 m.crate_def_map.extern_prelude().iter().for_each(|(name, &def)| { 398 m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| {
399 f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into()))); 399 f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into())));
400 }); 400 });
401 if let Some(prelude) = m.crate_def_map.prelude() { 401 if let Some(prelude) = m.crate_def_map.prelude {
402 let prelude_def_map = db.crate_def_map(prelude.krate); 402 let prelude_def_map = db.crate_def_map(prelude.krate);
403 prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| { 403 prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| {
404 f(name.clone(), ScopeDef::PerNs(res.def)); 404 f(name.clone(), ScopeDef::PerNs(res.def));