aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/body.rs2
-rw-r--r--crates/hir_def/src/find_path.rs4
-rw-r--r--crates/hir_def/src/nameres.rs18
-rw-r--r--crates/hir_def/src/resolver.rs10
4 files changed, 23 insertions, 11 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs
index 3b2dd0f6e..2c2c999dd 100644
--- a/crates/hir_def/src/body.rs
+++ b/crates/hir_def/src/body.rs
@@ -122,7 +122,7 @@ impl Expander {
122 122
123 let mut err = None; 123 let mut err = None;
124 let call_id = 124 let call_id =
125 macro_call.as_call_id_with_errors(db, self.crate_def_map.krate, resolver, &mut |e| { 125 macro_call.as_call_id_with_errors(db, self.crate_def_map.krate(), resolver, &mut |e| {
126 err.get_or_insert(e); 126 err.get_or_insert(e);
127 }); 127 });
128 let call_id = match call_id { 128 let call_id = match call_id {
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index d7b7b9cc0..db2d125ae 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -136,7 +136,7 @@ fn find_path_inner(
136 } 136 }
137 137
138 // - if the item is the crate root of a dependency crate, return the name from the extern prelude 138 // - if the item is the crate root of a dependency crate, return the name from the extern prelude
139 for (name, def_id) in &def_map.extern_prelude { 139 for (name, def_id) in def_map.extern_prelude() {
140 if item == ItemInNs::Types(*def_id) { 140 if item == ItemInNs::Types(*def_id) {
141 let name = scope_name.unwrap_or_else(|| name.clone()); 141 let name = scope_name.unwrap_or_else(|| name.clone());
142 return Some(ModPath::from_segments(PathKind::Plain, vec![name])); 142 return Some(ModPath::from_segments(PathKind::Plain, vec![name]));
@@ -144,7 +144,7 @@ fn find_path_inner(
144 } 144 }
145 145
146 // - if the item is in the prelude, return the name from there 146 // - if the item is in the prelude, return the name from there
147 if let Some(prelude_module) = def_map.prelude { 147 if let Some(prelude_module) = def_map.prelude() {
148 let prelude_def_map = db.crate_def_map(prelude_module.krate); 148 let prelude_def_map = db.crate_def_map(prelude_module.krate);
149 let prelude_scope: &crate::item_scope::ItemScope = 149 let prelude_scope: &crate::item_scope::ItemScope =
150 &prelude_def_map[prelude_module.local_id].scope; 150 &prelude_def_map[prelude_module.local_id].scope;
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index c3d3efc6b..23f960ad4 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -77,12 +77,12 @@ use crate::{
77pub struct DefMap { 77pub struct DefMap {
78 root: LocalModuleId, 78 root: LocalModuleId,
79 modules: Arena<ModuleData>, 79 modules: Arena<ModuleData>,
80 pub(crate) krate: CrateId, 80 krate: CrateId,
81 /// The prelude module for this crate. This either comes from an import 81 /// The prelude module for this crate. This either comes from an import
82 /// marked with the `prelude_import` attribute, or (in the normal case) from 82 /// marked with the `prelude_import` attribute, or (in the normal case) from
83 /// a dependency (`std` or `core`). 83 /// a dependency (`std` or `core`).
84 pub(crate) prelude: Option<ModuleId>, 84 prelude: Option<ModuleId>,
85 pub(crate) extern_prelude: FxHashMap<Name, ModuleDefId>, 85 extern_prelude: FxHashMap<Name, ModuleDefId>,
86 86
87 edition: Edition, 87 edition: Edition,
88 diagnostics: Vec<DefDiagnostic>, 88 diagnostics: Vec<DefDiagnostic>,
@@ -216,6 +216,18 @@ impl DefMap {
216 self.root 216 self.root
217 } 217 }
218 218
219 pub(crate) fn krate(&self) -> CrateId {
220 self.krate
221 }
222
223 pub(crate) fn prelude(&self) -> Option<ModuleId> {
224 self.prelude
225 }
226
227 pub(crate) fn extern_prelude(&self) -> impl Iterator<Item = (&Name, &ModuleDefId)> + '_ {
228 self.extern_prelude.iter()
229 }
230
219 pub(crate) fn resolve_path( 231 pub(crate) fn resolve_path(
220 &self, 232 &self,
221 db: &dyn DefDatabase, 233 db: &dyn DefDatabase,
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index a505bf2be..d48029b7d 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -416,7 +416,7 @@ impl Resolver {
416 let mut traits = FxHashSet::default(); 416 let mut traits = FxHashSet::default();
417 for scope in &self.scopes { 417 for scope in &self.scopes {
418 if let Scope::ModuleScope(m) = scope { 418 if let Scope::ModuleScope(m) = scope {
419 if let Some(prelude) = m.crate_def_map.prelude { 419 if let Some(prelude) = m.crate_def_map.prelude() {
420 let prelude_def_map = db.crate_def_map(prelude.krate); 420 let prelude_def_map = db.crate_def_map(prelude.krate);
421 traits.extend(prelude_def_map[prelude.local_id].scope.traits()); 421 traits.extend(prelude_def_map[prelude.local_id].scope.traits());
422 } 422 }
@@ -446,11 +446,11 @@ impl Resolver {
446 446
447 pub fn module(&self) -> Option<ModuleId> { 447 pub fn module(&self) -> Option<ModuleId> {
448 let (def_map, local_id) = self.module_scope()?; 448 let (def_map, local_id) = self.module_scope()?;
449 Some(ModuleId { krate: def_map.krate, local_id }) 449 Some(ModuleId { krate: def_map.krate(), local_id })
450 } 450 }
451 451
452 pub fn krate(&self) -> Option<CrateId> { 452 pub fn krate(&self) -> Option<CrateId> {
453 self.module_scope().map(|t| t.0.krate) 453 self.module_scope().map(|t| t.0.krate())
454 } 454 }
455 455
456 pub fn where_predicates_in_scope<'a>( 456 pub fn where_predicates_in_scope<'a>(
@@ -509,13 +509,13 @@ impl Scope {
509 seen.insert((name.clone(), scope)); 509 seen.insert((name.clone(), scope));
510 f(name.clone(), ScopeDef::PerNs(scope)); 510 f(name.clone(), ScopeDef::PerNs(scope));
511 }); 511 });
512 m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { 512 m.crate_def_map.extern_prelude().for_each(|(name, &def)| {
513 f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); 513 f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public)));
514 }); 514 });
515 BUILTIN_SCOPE.iter().for_each(|(name, &def)| { 515 BUILTIN_SCOPE.iter().for_each(|(name, &def)| {
516 f(name.clone(), ScopeDef::PerNs(def)); 516 f(name.clone(), ScopeDef::PerNs(def));
517 }); 517 });
518 if let Some(prelude) = m.crate_def_map.prelude { 518 if let Some(prelude) = m.crate_def_map.prelude() {
519 let prelude_def_map = db.crate_def_map(prelude.krate); 519 let prelude_def_map = db.crate_def_map(prelude.krate);
520 prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { 520 prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| {
521 let seen_tuple = (name.clone(), def); 521 let seen_tuple = (name.clone(), def);