mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Merge pull request #18702 from ChayimFriedman2/prep
minor: Use a record struct instead of a tuple for each namespace in `PerNs`
This commit is contained in:
commit
027daf1686
6 changed files with 162 additions and 133 deletions
|
@ -16,7 +16,7 @@ use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
per_ns::PerNs,
|
per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem},
|
||||||
visibility::{Visibility, VisibilityExplicitness},
|
visibility::{Visibility, VisibilityExplicitness},
|
||||||
AdtId, BuiltinType, ConstId, ExternCrateId, FxIndexMap, HasModule, ImplId, LocalModuleId,
|
AdtId, BuiltinType, ConstId, ExternCrateId, FxIndexMap, HasModule, ImplId, LocalModuleId,
|
||||||
Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
|
Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
|
||||||
|
@ -80,9 +80,9 @@ pub struct ItemScope {
|
||||||
/// Defs visible in this scope. This includes `declarations`, but also
|
/// Defs visible in this scope. This includes `declarations`, but also
|
||||||
/// imports. The imports belong to this module and can be resolved by using them on
|
/// imports. The imports belong to this module and can be resolved by using them on
|
||||||
/// the `use_imports_*` fields.
|
/// the `use_imports_*` fields.
|
||||||
types: FxIndexMap<Name, (ModuleDefId, Visibility, Option<ImportOrExternCrate>)>,
|
types: FxIndexMap<Name, TypesItem>,
|
||||||
values: FxIndexMap<Name, (ModuleDefId, Visibility, Option<ImportId>)>,
|
values: FxIndexMap<Name, ValuesItem>,
|
||||||
macros: FxIndexMap<Name, (MacroId, Visibility, Option<ImportId>)>,
|
macros: FxIndexMap<Name, MacrosItem>,
|
||||||
unresolved: FxHashSet<Name>,
|
unresolved: FxHashSet<Name>,
|
||||||
|
|
||||||
/// The defs declared in this scope. Each def has a single scope where it is
|
/// The defs declared in this scope. Each def has a single scope where it is
|
||||||
|
@ -92,7 +92,7 @@ pub struct ItemScope {
|
||||||
impls: Vec<ImplId>,
|
impls: Vec<ImplId>,
|
||||||
unnamed_consts: Vec<ConstId>,
|
unnamed_consts: Vec<ConstId>,
|
||||||
/// Traits imported via `use Trait as _;`.
|
/// Traits imported via `use Trait as _;`.
|
||||||
unnamed_trait_imports: FxHashMap<TraitId, (Visibility, Option<ImportId>)>,
|
unnamed_trait_imports: FxHashMap<TraitId, Item<()>>,
|
||||||
|
|
||||||
// the resolutions of the imports of this scope
|
// the resolutions of the imports of this scope
|
||||||
use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>,
|
use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>,
|
||||||
|
@ -187,7 +187,7 @@ impl ItemScope {
|
||||||
import = i;
|
import = i;
|
||||||
}
|
}
|
||||||
ImportOrDef::Def(ModuleDefId::MacroId(def)) => {
|
ImportOrDef::Def(ModuleDefId::MacroId(def)) => {
|
||||||
res.macros = Some((def, Visibility::Public, None));
|
res.macros = Some(Item { def, vis: Visibility::Public, import: None });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
|
@ -203,7 +203,7 @@ impl ItemScope {
|
||||||
import = i;
|
import = i;
|
||||||
}
|
}
|
||||||
ImportOrDef::Def(def) => {
|
ImportOrDef::Def(def) => {
|
||||||
res.types = Some((def, Visibility::Public, None));
|
res.types = Some(Item { def, vis: Visibility::Public, import: None });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
|
@ -219,7 +219,7 @@ impl ItemScope {
|
||||||
import = i;
|
import = i;
|
||||||
}
|
}
|
||||||
ImportOrDef::Def(def) => {
|
ImportOrDef::Def(def) => {
|
||||||
res.values = Some((def, Visibility::Public, None));
|
res.values = Some(Item { def, vis: Visibility::Public, import: None });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
|
@ -253,8 +253,8 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn modules_in_scope(&self) -> impl Iterator<Item = (ModuleId, Visibility)> + '_ {
|
pub(crate) fn modules_in_scope(&self) -> impl Iterator<Item = (ModuleId, Visibility)> + '_ {
|
||||||
self.types.values().copied().filter_map(|(def, vis, _)| match def {
|
self.types.values().filter_map(|ns| match ns.def {
|
||||||
ModuleDefId::ModuleId(module) => Some((module, vis)),
|
ModuleDefId::ModuleId(module) => Some((module, ns.vis)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -283,20 +283,20 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn type_(&self, name: &Name) -> Option<(ModuleDefId, Visibility)> {
|
pub(crate) fn type_(&self, name: &Name) -> Option<(ModuleDefId, Visibility)> {
|
||||||
self.types.get(name).copied().map(|(a, b, _)| (a, b))
|
self.types.get(name).map(|item| (item.def, item.vis))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// XXX: this is O(N) rather than O(1), try to not introduce new usages.
|
/// XXX: this is O(N) rather than O(1), try to not introduce new usages.
|
||||||
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility, /*declared*/ bool)> {
|
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility, /*declared*/ bool)> {
|
||||||
match item {
|
match item {
|
||||||
ItemInNs::Macros(def) => self.macros.iter().find_map(|(name, &(other_def, vis, i))| {
|
ItemInNs::Macros(def) => self.macros.iter().find_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((name, other_def.vis, other_def.import.is_none()))
|
||||||
}),
|
}),
|
||||||
ItemInNs::Types(def) => self.types.iter().find_map(|(name, &(other_def, vis, i))| {
|
ItemInNs::Types(def) => self.types.iter().find_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((name, other_def.vis, other_def.import.is_none()))
|
||||||
}),
|
}),
|
||||||
ItemInNs::Values(def) => self.values.iter().find_map(|(name, &(other_def, vis, i))| {
|
ItemInNs::Values(def) => self.values.iter().find_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((name, other_def.vis, other_def.import.is_none()))
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,22 +311,34 @@ impl ItemScope {
|
||||||
ItemInNs::Macros(def) => self
|
ItemInNs::Macros(def) => self
|
||||||
.macros
|
.macros
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(name, &(other_def, vis, i))| {
|
.filter_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((
|
||||||
|
name,
|
||||||
|
other_def.vis,
|
||||||
|
other_def.import.is_none(),
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.find_map(|(a, b, c)| cb(a, b, c)),
|
.find_map(|(a, b, c)| cb(a, b, c)),
|
||||||
ItemInNs::Types(def) => self
|
ItemInNs::Types(def) => self
|
||||||
.types
|
.types
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(name, &(other_def, vis, i))| {
|
.filter_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((
|
||||||
|
name,
|
||||||
|
other_def.vis,
|
||||||
|
other_def.import.is_none(),
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.find_map(|(a, b, c)| cb(a, b, c)),
|
.find_map(|(a, b, c)| cb(a, b, c)),
|
||||||
ItemInNs::Values(def) => self
|
ItemInNs::Values(def) => self
|
||||||
.values
|
.values
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(name, &(other_def, vis, i))| {
|
.filter_map(|(name, other_def)| {
|
||||||
(other_def == def).then_some((name, vis, i.is_none()))
|
(other_def.def == def).then_some((
|
||||||
|
name,
|
||||||
|
other_def.vis,
|
||||||
|
other_def.import.is_none(),
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.find_map(|(a, b, c)| cb(a, b, c)),
|
.find_map(|(a, b, c)| cb(a, b, c)),
|
||||||
}
|
}
|
||||||
|
@ -335,7 +347,7 @@ impl ItemScope {
|
||||||
pub(crate) fn traits(&self) -> impl Iterator<Item = TraitId> + '_ {
|
pub(crate) fn traits(&self) -> impl Iterator<Item = TraitId> + '_ {
|
||||||
self.types
|
self.types
|
||||||
.values()
|
.values()
|
||||||
.filter_map(|&(def, _, _)| match def {
|
.filter_map(|def| match def.def {
|
||||||
ModuleDefId::TraitId(t) => Some(t),
|
ModuleDefId::TraitId(t) => Some(t),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -344,13 +356,13 @@ impl ItemScope {
|
||||||
|
|
||||||
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (Option<Name>, PerNs)> + '_ {
|
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (Option<Name>, PerNs)> + '_ {
|
||||||
self.entries().map(|(name, res)| (Some(name.clone()), res)).chain(
|
self.entries().map(|(name, res)| (Some(name.clone()), res)).chain(
|
||||||
self.unnamed_trait_imports.iter().map(|(tr, (vis, i))| {
|
self.unnamed_trait_imports.iter().map(|(tr, trait_)| {
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
PerNs::types(
|
PerNs::types(
|
||||||
ModuleDefId::TraitId(*tr),
|
ModuleDefId::TraitId(*tr),
|
||||||
*vis,
|
trait_.vis,
|
||||||
i.map(ImportOrExternCrate::Import),
|
trait_.import.map(ImportOrExternCrate::Import),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
@ -464,12 +476,12 @@ impl ItemScope {
|
||||||
|
|
||||||
// FIXME: This is only used in collection, we should move the relevant parts of it out of ItemScope
|
// FIXME: This is only used in collection, we should move the relevant parts of it out of ItemScope
|
||||||
pub(crate) fn unnamed_trait_vis(&self, tr: TraitId) -> Option<Visibility> {
|
pub(crate) fn unnamed_trait_vis(&self, tr: TraitId) -> Option<Visibility> {
|
||||||
self.unnamed_trait_imports.get(&tr).copied().map(|(a, _)| a)
|
self.unnamed_trait_imports.get(&tr).map(|trait_| trait_.vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push_unnamed_trait(&mut self, tr: TraitId, vis: Visibility) {
|
pub(crate) fn push_unnamed_trait(&mut self, tr: TraitId, vis: Visibility) {
|
||||||
// FIXME: import
|
// FIXME: import
|
||||||
self.unnamed_trait_imports.insert(tr, (vis, None));
|
self.unnamed_trait_imports.insert(tr, Item { def: (), vis, import: None });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push_res_with_import(
|
pub(crate) fn push_res_with_import(
|
||||||
|
@ -502,7 +514,7 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
None | Some(ImportType::Glob(_)) => None,
|
None | Some(ImportType::Glob(_)) => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types.insert(
|
self.use_imports_types.insert(
|
||||||
import,
|
import,
|
||||||
|
@ -513,7 +525,7 @@ impl ItemScope {
|
||||||
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
||||||
ImportOrDef::ExternCrate(import)
|
ImportOrDef::ExternCrate(import)
|
||||||
}
|
}
|
||||||
None => ImportOrDef::Def(fld.0),
|
None => ImportOrDef::Def(fld.def),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -540,7 +552,7 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
None | Some(ImportType::Glob(_)) => None,
|
None | Some(ImportType::Glob(_)) => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types.insert(
|
self.use_imports_types.insert(
|
||||||
import,
|
import,
|
||||||
|
@ -551,7 +563,7 @@ impl ItemScope {
|
||||||
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
||||||
ImportOrDef::ExternCrate(import)
|
ImportOrDef::ExternCrate(import)
|
||||||
}
|
}
|
||||||
None => ImportOrDef::Def(fld.0),
|
None => ImportOrDef::Def(fld.def),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -579,13 +591,13 @@ impl ItemScope {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(import),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values.insert(
|
self.use_imports_values.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
match prev {
|
||||||
Some(import) => ImportOrDef::Import(import),
|
Some(import) => ImportOrDef::Import(import),
|
||||||
None => ImportOrDef::Def(fld.0),
|
None => ImportOrDef::Def(fld.def),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -599,13 +611,13 @@ impl ItemScope {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(import),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values.insert(
|
self.use_imports_values.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
match prev {
|
||||||
Some(import) => ImportOrDef::Import(import),
|
Some(import) => ImportOrDef::Import(import),
|
||||||
None => ImportOrDef::Def(fld.0),
|
None => ImportOrDef::Def(fld.def),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -631,13 +643,13 @@ impl ItemScope {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(import),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
match prev {
|
||||||
Some(import) => ImportOrDef::Import(import),
|
Some(import) => ImportOrDef::Import(import),
|
||||||
None => ImportOrDef::Def(fld.0.into()),
|
None => ImportOrDef::Def(fld.def.into()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -651,13 +663,13 @@ impl ItemScope {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(import),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.2, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
match prev {
|
||||||
Some(import) => ImportOrDef::Import(import),
|
Some(import) => ImportOrDef::Import(import),
|
||||||
None => ImportOrDef::Def(fld.0.into()),
|
None => ImportOrDef::Def(fld.def.into()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -680,19 +692,19 @@ impl ItemScope {
|
||||||
pub(crate) fn censor_non_proc_macros(&mut self, this_module: ModuleId) {
|
pub(crate) fn censor_non_proc_macros(&mut self, this_module: ModuleId) {
|
||||||
self.types
|
self.types
|
||||||
.values_mut()
|
.values_mut()
|
||||||
.map(|(_, vis, _)| vis)
|
.map(|def| &mut def.vis)
|
||||||
.chain(self.values.values_mut().map(|(_, vis, _)| vis))
|
.chain(self.values.values_mut().map(|def| &mut def.vis))
|
||||||
.chain(self.unnamed_trait_imports.values_mut().map(|(vis, _)| vis))
|
.chain(self.unnamed_trait_imports.values_mut().map(|def| &mut def.vis))
|
||||||
.for_each(|vis| {
|
.for_each(|vis| {
|
||||||
*vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit)
|
*vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (mac, vis, import) in self.macros.values_mut() {
|
for mac in self.macros.values_mut() {
|
||||||
if matches!(mac, MacroId::ProcMacroId(_) if import.is_none()) {
|
if matches!(mac.def, MacroId::ProcMacroId(_) if mac.import.is_none()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
*vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit);
|
mac.vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,23 +719,23 @@ impl ItemScope {
|
||||||
name.map_or("_".to_owned(), |name| name.display(db, Edition::LATEST).to_string())
|
name.map_or("_".to_owned(), |name| name.display(db, Edition::LATEST).to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((.., i)) = def.types {
|
if let Some(Item { import, .. }) = def.types {
|
||||||
buf.push_str(" t");
|
buf.push_str(" t");
|
||||||
match i {
|
match import {
|
||||||
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
|
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
|
||||||
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
|
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some((.., i)) = def.values {
|
if let Some(Item { import, .. }) = def.values {
|
||||||
buf.push_str(" v");
|
buf.push_str(" v");
|
||||||
if i.is_some() {
|
if import.is_some() {
|
||||||
buf.push('i');
|
buf.push('i');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some((.., i)) = def.macros {
|
if let Some(Item { import, .. }) = def.macros {
|
||||||
buf.push_str(" m");
|
buf.push_str(" m");
|
||||||
if i.is_some() {
|
if import.is_some() {
|
||||||
buf.push('i');
|
buf.push('i');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,19 +793,19 @@ impl ItemScope {
|
||||||
pub(crate) fn update_visibility_types(&mut self, name: &Name, vis: Visibility) {
|
pub(crate) fn update_visibility_types(&mut self, name: &Name, vis: Visibility) {
|
||||||
let res =
|
let res =
|
||||||
self.types.get_mut(name).expect("tried to update visibility of non-existent type");
|
self.types.get_mut(name).expect("tried to update visibility of non-existent type");
|
||||||
res.1 = vis;
|
res.vis = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_visibility_values(&mut self, name: &Name, vis: Visibility) {
|
pub(crate) fn update_visibility_values(&mut self, name: &Name, vis: Visibility) {
|
||||||
let res =
|
let res =
|
||||||
self.values.get_mut(name).expect("tried to update visibility of non-existent value");
|
self.values.get_mut(name).expect("tried to update visibility of non-existent value");
|
||||||
res.1 = vis;
|
res.vis = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_visibility_macros(&mut self, name: &Name, vis: Visibility) {
|
pub(crate) fn update_visibility_macros(&mut self, name: &Name, vis: Visibility) {
|
||||||
let res =
|
let res =
|
||||||
self.macros.get_mut(name).expect("tried to update visibility of non-existent macro");
|
self.macros.get_mut(name).expect("tried to update visibility of non-existent macro");
|
||||||
res.1 = vis;
|
res.vis = vis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ use crate::{
|
||||||
ResolveMode,
|
ResolveMode,
|
||||||
},
|
},
|
||||||
path::{ImportAlias, ModPath, PathKind},
|
path::{ImportAlias, ModPath, PathKind},
|
||||||
per_ns::PerNs,
|
per_ns::{Item, PerNs},
|
||||||
tt,
|
tt,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantLoc,
|
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantLoc,
|
||||||
|
@ -523,7 +523,7 @@ impl DefCollector<'_> {
|
||||||
self.def_map.resolve_path(self.db, DefMap::ROOT, &path, BuiltinShadowMode::Other, None);
|
self.def_map.resolve_path(self.db, DefMap::ROOT, &path, BuiltinShadowMode::Other, None);
|
||||||
|
|
||||||
match per_ns.types {
|
match per_ns.types {
|
||||||
Some((ModuleDefId::ModuleId(m), _, import)) => {
|
Some(Item { def: ModuleDefId::ModuleId(m), import, .. }) => {
|
||||||
// FIXME: This should specifically look for a glob import somehow and record that here
|
// FIXME: This should specifically look for a glob import somehow and record that here
|
||||||
self.def_map.prelude = Some((
|
self.def_map.prelude = Some((
|
||||||
m,
|
m,
|
||||||
|
@ -1069,9 +1069,9 @@ impl DefCollector<'_> {
|
||||||
//
|
//
|
||||||
// This has been historically allowed, but may be not allowed in future
|
// This has been historically allowed, but may be not allowed in future
|
||||||
// https://github.com/rust-lang/rust/issues/127909
|
// https://github.com/rust-lang/rust/issues/127909
|
||||||
if let Some((_, v, it)) = defs.types.as_mut() {
|
if let Some(def) = defs.types.as_mut() {
|
||||||
let is_extern_crate_reimport_without_prefix = || {
|
let is_extern_crate_reimport_without_prefix = || {
|
||||||
let Some(ImportOrExternCrate::ExternCrate(_)) = it else {
|
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let Some(ImportType::Import(id)) = def_import_type else {
|
let Some(ImportType::Import(id)) = def_import_type else {
|
||||||
|
@ -1086,16 +1086,16 @@ impl DefCollector<'_> {
|
||||||
path.segments().len() < 2
|
path.segments().len() < 2
|
||||||
};
|
};
|
||||||
if is_extern_crate_reimport_without_prefix() {
|
if is_extern_crate_reimport_without_prefix() {
|
||||||
*v = vis;
|
def.vis = vis;
|
||||||
} else {
|
} else {
|
||||||
*v = v.min(vis, &self.def_map).unwrap_or(vis);
|
def.vis = def.vis.min(vis, &self.def_map).unwrap_or(vis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some((_, v, _)) = defs.values.as_mut() {
|
if let Some(def) = defs.values.as_mut() {
|
||||||
*v = v.min(vis, &self.def_map).unwrap_or(vis);
|
def.vis = def.vis.min(vis, &self.def_map).unwrap_or(vis);
|
||||||
}
|
}
|
||||||
if let Some((_, v, _)) = defs.macros.as_mut() {
|
if let Some(def) = defs.macros.as_mut() {
|
||||||
*v = v.min(vis, &self.def_map).unwrap_or(vis);
|
def.vis = def.vis.min(vis, &self.def_map).unwrap_or(vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
@ -1106,12 +1106,12 @@ impl DefCollector<'_> {
|
||||||
// Multiple globs may import the same item and they may override visibility from
|
// Multiple globs may import the same item and they may override visibility from
|
||||||
// previously resolved globs. Handle overrides here and leave the rest to
|
// previously resolved globs. Handle overrides here and leave the rest to
|
||||||
// `ItemScope::push_res_with_import()`.
|
// `ItemScope::push_res_with_import()`.
|
||||||
if let Some((def, def_vis, _)) = defs.types {
|
if let Some(def) = defs.types {
|
||||||
if let Some((prev_def, prev_vis, _)) = prev_defs.types {
|
if let Some(prev_def) = prev_defs.types {
|
||||||
if def == prev_def
|
if def.def == prev_def.def
|
||||||
&& self.from_glob_import.contains_type(module_id, name.clone())
|
&& self.from_glob_import.contains_type(module_id, name.clone())
|
||||||
&& def_vis != prev_vis
|
&& def.vis != prev_def.vis
|
||||||
&& def_vis.max(prev_vis, &self.def_map) == Some(def_vis)
|
&& def.vis.max(prev_def.vis, &self.def_map) == Some(def.vis)
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
// This import is being handled here, don't pass it down to
|
// This import is being handled here, don't pass it down to
|
||||||
|
@ -1119,41 +1119,41 @@ impl DefCollector<'_> {
|
||||||
defs.types = None;
|
defs.types = None;
|
||||||
self.def_map.modules[module_id]
|
self.def_map.modules[module_id]
|
||||||
.scope
|
.scope
|
||||||
.update_visibility_types(name, def_vis);
|
.update_visibility_types(name, def.vis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((def, def_vis, _)) = defs.values {
|
if let Some(def) = defs.values {
|
||||||
if let Some((prev_def, prev_vis, _)) = prev_defs.values {
|
if let Some(prev_def) = prev_defs.values {
|
||||||
if def == prev_def
|
if def.def == prev_def.def
|
||||||
&& self.from_glob_import.contains_value(module_id, name.clone())
|
&& self.from_glob_import.contains_value(module_id, name.clone())
|
||||||
&& def_vis != prev_vis
|
&& def.vis != prev_def.vis
|
||||||
&& def_vis.max(prev_vis, &self.def_map) == Some(def_vis)
|
&& def.vis.max(prev_def.vis, &self.def_map) == Some(def.vis)
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
// See comment above.
|
// See comment above.
|
||||||
defs.values = None;
|
defs.values = None;
|
||||||
self.def_map.modules[module_id]
|
self.def_map.modules[module_id]
|
||||||
.scope
|
.scope
|
||||||
.update_visibility_values(name, def_vis);
|
.update_visibility_values(name, def.vis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((def, def_vis, _)) = defs.macros {
|
if let Some(def) = defs.macros {
|
||||||
if let Some((prev_def, prev_vis, _)) = prev_defs.macros {
|
if let Some(prev_def) = prev_defs.macros {
|
||||||
if def == prev_def
|
if def.def == prev_def.def
|
||||||
&& self.from_glob_import.contains_macro(module_id, name.clone())
|
&& self.from_glob_import.contains_macro(module_id, name.clone())
|
||||||
&& def_vis != prev_vis
|
&& def.vis != prev_def.vis
|
||||||
&& def_vis.max(prev_vis, &self.def_map) == Some(def_vis)
|
&& def.vis.max(prev_def.vis, &self.def_map) == Some(def.vis)
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
// See comment above.
|
// See comment above.
|
||||||
defs.macros = None;
|
defs.macros = None;
|
||||||
self.def_map.modules[module_id]
|
self.def_map.modules[module_id]
|
||||||
.scope
|
.scope
|
||||||
.update_visibility_macros(name, def_vis);
|
.update_visibility_macros(name, def.vis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ impl PerNs {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
expected: Option<MacroSubNs>,
|
expected: Option<MacroSubNs>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.macros = self.macros.filter(|&(id, _, _)| {
|
self.macros = self.macros.filter(|def| {
|
||||||
let this = MacroSubNs::from_id(db, id);
|
let this = MacroSubNs::from_id(db, def.def);
|
||||||
sub_namespace_match(Some(this), expected)
|
sub_namespace_match(Some(this), expected)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ impl DefMap {
|
||||||
original_module: LocalModuleId,
|
original_module: LocalModuleId,
|
||||||
) -> ResolvePathResult {
|
) -> ResolvePathResult {
|
||||||
for (i, segment) in segments {
|
for (i, segment) in segments {
|
||||||
let (curr, vis, imp) = match curr_per_ns.take_types_full() {
|
let curr = match curr_per_ns.take_types_full() {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
// we still have path segments left, but the path so far
|
// we still have path segments left, but the path so far
|
||||||
|
@ -424,7 +424,7 @@ impl DefMap {
|
||||||
};
|
};
|
||||||
// resolve segment in curr
|
// resolve segment in curr
|
||||||
|
|
||||||
curr_per_ns = match curr {
|
curr_per_ns = match curr.def {
|
||||||
ModuleDefId::ModuleId(module) => {
|
ModuleDefId::ModuleId(module) => {
|
||||||
if module.krate != self.krate {
|
if module.krate != self.krate {
|
||||||
let path = ModPath::from_segments(
|
let path = ModPath::from_segments(
|
||||||
|
@ -492,7 +492,7 @@ impl DefMap {
|
||||||
Some(res) => res,
|
Some(res) => res,
|
||||||
None => {
|
None => {
|
||||||
return ResolvePathResult::new(
|
return ResolvePathResult::new(
|
||||||
PerNs::types(e.into(), vis, imp),
|
PerNs::types(e.into(), curr.vis, curr.import),
|
||||||
ReachedFixedPoint::Yes,
|
ReachedFixedPoint::Yes,
|
||||||
Some(i),
|
Some(i),
|
||||||
false,
|
false,
|
||||||
|
@ -510,7 +510,7 @@ impl DefMap {
|
||||||
);
|
);
|
||||||
|
|
||||||
return ResolvePathResult::new(
|
return ResolvePathResult::new(
|
||||||
PerNs::types(s, vis, imp),
|
PerNs::types(s, curr.vis, curr.import),
|
||||||
ReachedFixedPoint::Yes,
|
ReachedFixedPoint::Yes,
|
||||||
Some(i),
|
Some(i),
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -331,7 +331,7 @@ pub type Ty = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (_, res) in module_data.scope.resolutions() {
|
for (_, res) in module_data.scope.resolutions() {
|
||||||
match res.values.map(|(a, _, _)| a).or(res.types.map(|(a, _, _)| a)).unwrap() {
|
match res.values.map(|it| it.def).or(res.types.map(|it| it.def)).unwrap() {
|
||||||
ModuleDefId::FunctionId(f) => _ = db.function_data(f),
|
ModuleDefId::FunctionId(f) => _ = db.function_data(f),
|
||||||
ModuleDefId::AdtId(adt) => match adt {
|
ModuleDefId::AdtId(adt) => match adt {
|
||||||
AdtId::StructId(it) => _ = db.struct_data(it),
|
AdtId::StructId(it) => _ = db.struct_data(it),
|
||||||
|
|
|
@ -28,11 +28,22 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Item<Def, Import = ImportId> {
|
||||||
|
pub def: Def,
|
||||||
|
pub vis: Visibility,
|
||||||
|
pub import: Option<Import>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type TypesItem = Item<ModuleDefId, ImportOrExternCrate>;
|
||||||
|
pub type ValuesItem = Item<ModuleDefId>;
|
||||||
|
pub type MacrosItem = Item<MacroId>;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
||||||
pub struct PerNs {
|
pub struct PerNs {
|
||||||
pub types: Option<(ModuleDefId, Visibility, Option<ImportOrExternCrate>)>,
|
pub types: Option<TypesItem>,
|
||||||
pub values: Option<(ModuleDefId, Visibility, Option<ImportId>)>,
|
pub values: Option<ValuesItem>,
|
||||||
pub macros: Option<(MacroId, Visibility, Option<ImportId>)>,
|
pub macros: Option<MacrosItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PerNs {
|
impl PerNs {
|
||||||
|
@ -48,29 +59,33 @@ impl PerNs {
|
||||||
PerNs { types: None, values: None, macros: None }
|
PerNs { types: None, values: None, macros: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn values(t: ModuleDefId, v: Visibility, i: Option<ImportId>) -> PerNs {
|
pub fn values(def: ModuleDefId, vis: Visibility, import: Option<ImportId>) -> PerNs {
|
||||||
PerNs { types: None, values: Some((t, v, i)), macros: None }
|
PerNs { types: None, values: Some(Item { def, vis, import }), macros: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn types(t: ModuleDefId, v: Visibility, i: Option<ImportOrExternCrate>) -> PerNs {
|
pub fn types(def: ModuleDefId, vis: Visibility, import: Option<ImportOrExternCrate>) -> PerNs {
|
||||||
PerNs { types: Some((t, v, i)), values: None, macros: None }
|
PerNs { types: Some(Item { def, vis, import }), values: None, macros: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn both(
|
pub fn both(
|
||||||
types: ModuleDefId,
|
types: ModuleDefId,
|
||||||
values: ModuleDefId,
|
values: ModuleDefId,
|
||||||
v: Visibility,
|
vis: Visibility,
|
||||||
i: Option<ImportOrExternCrate>,
|
import: Option<ImportOrExternCrate>,
|
||||||
) -> PerNs {
|
) -> PerNs {
|
||||||
PerNs {
|
PerNs {
|
||||||
types: Some((types, v, i)),
|
types: Some(Item { def: types, vis, import }),
|
||||||
values: Some((values, v, i.and_then(ImportOrExternCrate::into_import))),
|
values: Some(Item {
|
||||||
|
def: values,
|
||||||
|
vis,
|
||||||
|
import: import.and_then(ImportOrExternCrate::into_import),
|
||||||
|
}),
|
||||||
macros: None,
|
macros: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macros(macro_: MacroId, v: Visibility, i: Option<ImportId>) -> PerNs {
|
pub fn macros(def: MacroId, vis: Visibility, import: Option<ImportId>) -> PerNs {
|
||||||
PerNs { types: None, values: None, macros: Some((macro_, v, i)) }
|
PerNs { types: None, values: None, macros: Some(Item { def, vis, import }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_none(&self) -> bool {
|
pub fn is_none(&self) -> bool {
|
||||||
|
@ -82,43 +97,43 @@ impl PerNs {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_types(self) -> Option<ModuleDefId> {
|
pub fn take_types(self) -> Option<ModuleDefId> {
|
||||||
self.types.map(|it| it.0)
|
self.types.map(|it| it.def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_types_full(self) -> Option<(ModuleDefId, Visibility, Option<ImportOrExternCrate>)> {
|
pub fn take_types_full(self) -> Option<TypesItem> {
|
||||||
self.types
|
self.types
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_values(self) -> Option<ModuleDefId> {
|
pub fn take_values(self) -> Option<ModuleDefId> {
|
||||||
self.values.map(|it| it.0)
|
self.values.map(|it| it.def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportId>)> {
|
pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportId>)> {
|
||||||
self.values.map(|it| (it.0, it.2))
|
self.values.map(|it| (it.def, it.import))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_macros(self) -> Option<MacroId> {
|
pub fn take_macros(self) -> Option<MacroId> {
|
||||||
self.macros.map(|it| it.0)
|
self.macros.map(|it| it.def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportId>)> {
|
pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportId>)> {
|
||||||
self.macros.map(|it| (it.0, it.2))
|
self.macros.map(|it| (it.def, it.import))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs {
|
pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs {
|
||||||
let _p = tracing::info_span!("PerNs::filter_visibility").entered();
|
let _p = tracing::info_span!("PerNs::filter_visibility").entered();
|
||||||
PerNs {
|
PerNs {
|
||||||
types: self.types.filter(|&(_, v, _)| f(v)),
|
types: self.types.filter(|def| f(def.vis)),
|
||||||
values: self.values.filter(|&(_, v, _)| f(v)),
|
values: self.values.filter(|def| f(def.vis)),
|
||||||
macros: self.macros.filter(|&(_, v, _)| f(v)),
|
macros: self.macros.filter(|def| f(def.vis)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_visibility(self, vis: Visibility) -> PerNs {
|
pub fn with_visibility(self, vis: Visibility) -> PerNs {
|
||||||
PerNs {
|
PerNs {
|
||||||
types: self.types.map(|(it, _, c)| (it, vis, c)),
|
types: self.types.map(|def| Item { vis, ..def }),
|
||||||
values: self.values.map(|(it, _, c)| (it, vis, c)),
|
values: self.values.map(|def| Item { vis, ..def }),
|
||||||
macros: self.macros.map(|(it, _, import)| (it, vis, import)),
|
macros: self.macros.map(|def| Item { vis, ..def }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,15 +156,17 @@ impl PerNs {
|
||||||
pub fn iter_items(self) -> impl Iterator<Item = (ItemInNs, Option<ImportOrExternCrate>)> {
|
pub fn iter_items(self) -> impl Iterator<Item = (ItemInNs, Option<ImportOrExternCrate>)> {
|
||||||
let _p = tracing::info_span!("PerNs::iter_items").entered();
|
let _p = tracing::info_span!("PerNs::iter_items").entered();
|
||||||
self.types
|
self.types
|
||||||
.map(|it| (ItemInNs::Types(it.0), it.2))
|
.map(|it| (ItemInNs::Types(it.def), it.import))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(
|
.chain(
|
||||||
self.values
|
self.values.map(|it| {
|
||||||
.map(|it| (ItemInNs::Values(it.0), it.2.map(ImportOrExternCrate::Import))),
|
(ItemInNs::Values(it.def), it.import.map(ImportOrExternCrate::Import))
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.chain(
|
.chain(
|
||||||
self.macros
|
self.macros.map(|it| {
|
||||||
.map(|it| (ItemInNs::Macros(it.0), it.2.map(ImportOrExternCrate::Import))),
|
(ItemInNs::Macros(it.def), it.import.map(ImportOrExternCrate::Import))
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -933,8 +933,8 @@ impl ModuleItemMap {
|
||||||
Some(ResolveValueResult::ValueNs(value, import))
|
Some(ResolveValueResult::ValueNs(value, import))
|
||||||
}
|
}
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
let (def, _, import) = module_def.take_types_full()?;
|
let def = module_def.take_types_full()?;
|
||||||
let ty = match def {
|
let ty = match def.def {
|
||||||
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
||||||
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
||||||
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
||||||
|
@ -948,7 +948,7 @@ impl ModuleItemMap {
|
||||||
| ModuleDefId::MacroId(_)
|
| ModuleDefId::MacroId(_)
|
||||||
| ModuleDefId::StaticId(_) => return None,
|
| ModuleDefId::StaticId(_) => return None,
|
||||||
};
|
};
|
||||||
Some(ResolveValueResult::Partial(ty, idx, import))
|
Some(ResolveValueResult::Partial(ty, idx, def.import))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -986,8 +986,8 @@ fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportId>)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_type_ns(per_ns: PerNs) -> Option<(TypeNs, Option<ImportOrExternCrate>)> {
|
fn to_type_ns(per_ns: PerNs) -> Option<(TypeNs, Option<ImportOrExternCrate>)> {
|
||||||
let (def, _, import) = per_ns.take_types_full()?;
|
let def = per_ns.take_types_full()?;
|
||||||
let res = match def {
|
let res = match def.def {
|
||||||
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
||||||
ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it),
|
ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it),
|
||||||
|
|
||||||
|
@ -1003,7 +1003,7 @@ fn to_type_ns(per_ns: PerNs) -> Option<(TypeNs, Option<ImportOrExternCrate>)> {
|
||||||
| ModuleDefId::StaticId(_)
|
| ModuleDefId::StaticId(_)
|
||||||
| ModuleDefId::ModuleId(_) => return None,
|
| ModuleDefId::ModuleId(_) => return None,
|
||||||
};
|
};
|
||||||
Some((res, import))
|
Some((res, def.import))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -1019,14 +1019,14 @@ impl ScopeNames {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_per_ns(&mut self, name: &Name, def: PerNs) {
|
fn add_per_ns(&mut self, name: &Name, def: PerNs) {
|
||||||
if let &Some((ty, _, _)) = &def.types {
|
if let Some(ty) = &def.types {
|
||||||
self.add(name, ScopeDef::ModuleDef(ty))
|
self.add(name, ScopeDef::ModuleDef(ty.def))
|
||||||
}
|
}
|
||||||
if let &Some((def, _, _)) = &def.values {
|
if let Some(def) = &def.values {
|
||||||
self.add(name, ScopeDef::ModuleDef(def))
|
self.add(name, ScopeDef::ModuleDef(def.def))
|
||||||
}
|
}
|
||||||
if let &Some((mac, _, _)) = &def.macros {
|
if let Some(mac) = &def.macros {
|
||||||
self.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)))
|
self.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac.def)))
|
||||||
}
|
}
|
||||||
if def.is_none() {
|
if def.is_none() {
|
||||||
self.add(name, ScopeDef::Unknown)
|
self.add(name, ScopeDef::Unknown)
|
||||||
|
|
Loading…
Reference in a new issue