From 5f319ca7eeec52f311135117156fa06186146b07 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 20 Jan 2021 18:17:48 +0100 Subject: DefMap: hide remaining crate-visible fields --- crates/hir_def/src/body.rs | 2 +- crates/hir_def/src/find_path.rs | 4 ++-- crates/hir_def/src/nameres.rs | 18 +++++++++++++++--- crates/hir_def/src/resolver.rs | 10 +++++----- 4 files changed, 23 insertions(+), 11 deletions(-) (limited to 'crates/hir_def/src') 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 { let mut err = None; let call_id = - macro_call.as_call_id_with_errors(db, self.crate_def_map.krate, resolver, &mut |e| { + macro_call.as_call_id_with_errors(db, self.crate_def_map.krate(), resolver, &mut |e| { err.get_or_insert(e); }); 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( } // - if the item is the crate root of a dependency crate, return the name from the extern prelude - for (name, def_id) in &def_map.extern_prelude { + for (name, def_id) in def_map.extern_prelude() { if item == ItemInNs::Types(*def_id) { let name = scope_name.unwrap_or_else(|| name.clone()); return Some(ModPath::from_segments(PathKind::Plain, vec![name])); @@ -144,7 +144,7 @@ fn find_path_inner( } // - if the item is in the prelude, return the name from there - if let Some(prelude_module) = def_map.prelude { + if let Some(prelude_module) = def_map.prelude() { let prelude_def_map = db.crate_def_map(prelude_module.krate); let prelude_scope: &crate::item_scope::ItemScope = &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::{ pub struct DefMap { root: LocalModuleId, modules: Arena, - pub(crate) krate: CrateId, + krate: CrateId, /// The prelude module for this crate. This either comes from an import /// marked with the `prelude_import` attribute, or (in the normal case) from /// a dependency (`std` or `core`). - pub(crate) prelude: Option, - pub(crate) extern_prelude: FxHashMap, + prelude: Option, + extern_prelude: FxHashMap, edition: Edition, diagnostics: Vec, @@ -216,6 +216,18 @@ impl DefMap { self.root } + pub(crate) fn krate(&self) -> CrateId { + self.krate + } + + pub(crate) fn prelude(&self) -> Option { + self.prelude + } + + pub(crate) fn extern_prelude(&self) -> impl Iterator + '_ { + self.extern_prelude.iter() + } + pub(crate) fn resolve_path( &self, 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 { let mut traits = FxHashSet::default(); for scope in &self.scopes { if let Scope::ModuleScope(m) = scope { - if let Some(prelude) = m.crate_def_map.prelude { + if let Some(prelude) = m.crate_def_map.prelude() { let prelude_def_map = db.crate_def_map(prelude.krate); traits.extend(prelude_def_map[prelude.local_id].scope.traits()); } @@ -446,11 +446,11 @@ impl Resolver { pub fn module(&self) -> Option { let (def_map, local_id) = self.module_scope()?; - Some(ModuleId { krate: def_map.krate, local_id }) + Some(ModuleId { krate: def_map.krate(), local_id }) } pub fn krate(&self) -> Option { - self.module_scope().map(|t| t.0.krate) + self.module_scope().map(|t| t.0.krate()) } pub fn where_predicates_in_scope<'a>( @@ -509,13 +509,13 @@ impl Scope { seen.insert((name.clone(), scope)); f(name.clone(), ScopeDef::PerNs(scope)); }); - m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { + m.crate_def_map.extern_prelude().for_each(|(name, &def)| { f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); }); BUILTIN_SCOPE.iter().for_each(|(name, &def)| { f(name.clone(), ScopeDef::PerNs(def)); }); - if let Some(prelude) = m.crate_def_map.prelude { + if let Some(prelude) = m.crate_def_map.prelude() { let prelude_def_map = db.crate_def_map(prelude.krate); prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { let seen_tuple = (name.clone(), def); -- cgit v1.2.3