DefMap: hide remaining crate-visible fields

This commit is contained in:
Jonas Schievink 2021-01-20 18:17:48 +01:00
parent e62533c3ec
commit 5f319ca7ee
4 changed files with 23 additions and 11 deletions

View File

@ -122,7 +122,7 @@ pub(crate) fn enter_expand<T: ast::AstNode>(
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 {

View File

@ -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;

View File

@ -77,12 +77,12 @@
pub struct DefMap {
root: LocalModuleId,
modules: Arena<ModuleData>,
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<ModuleId>,
pub(crate) extern_prelude: FxHashMap<Name, ModuleDefId>,
prelude: Option<ModuleId>,
extern_prelude: FxHashMap<Name, ModuleDefId>,
edition: Edition,
diagnostics: Vec<DefDiagnostic>,
@ -216,6 +216,18 @@ pub fn root(&self) -> LocalModuleId {
self.root
}
pub(crate) fn krate(&self) -> CrateId {
self.krate
}
pub(crate) fn prelude(&self) -> Option<ModuleId> {
self.prelude
}
pub(crate) fn extern_prelude(&self) -> impl Iterator<Item = (&Name, &ModuleDefId)> + '_ {
self.extern_prelude.iter()
}
pub(crate) fn resolve_path(
&self,
db: &dyn DefDatabase,

View File

@ -416,7 +416,7 @@ pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
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 @@ fn resolve_local_macro_def(&self, path: &ModPath) -> Option<MacroDefId> {
pub fn module(&self) -> Option<ModuleId> {
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<CrateId> {
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 @@ fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef))
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);