nameres: collect unnamed consts
This commit is contained in:
parent
3e7ac2b830
commit
f04f38d3d7
@ -11,7 +11,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
|||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ImplId,
|
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ConstId, ImplId,
|
||||||
LocalModuleId, MacroDefId, ModuleDefId, ModuleId, TraitId,
|
LocalModuleId, MacroDefId, ModuleDefId, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ pub struct ItemScope {
|
|||||||
|
|
||||||
defs: Vec<ModuleDefId>,
|
defs: Vec<ModuleDefId>,
|
||||||
impls: Vec<ImplId>,
|
impls: Vec<ImplId>,
|
||||||
|
unnamed_consts: Vec<ConstId>,
|
||||||
/// Traits imported via `use Trait as _;`.
|
/// Traits imported via `use Trait as _;`.
|
||||||
unnamed_trait_imports: FxHashMap<TraitId, Visibility>,
|
unnamed_trait_imports: FxHashMap<TraitId, Visibility>,
|
||||||
/// Macros visible in current module in legacy textual scope
|
/// Macros visible in current module in legacy textual scope
|
||||||
@ -156,6 +157,10 @@ impl ItemScope {
|
|||||||
self.impls.push(imp)
|
self.impls.push(imp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn define_unnamed_const(&mut self, konst: ConstId) {
|
||||||
|
self.unnamed_consts.push(konst);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn define_legacy_macro(&mut self, name: Name, mac: MacroDefId) {
|
pub(crate) fn define_legacy_macro(&mut self, name: Name, mac: MacroDefId) {
|
||||||
self.legacy_macros.insert(name, mac);
|
self.legacy_macros.insert(name, mac);
|
||||||
}
|
}
|
||||||
@ -295,6 +300,7 @@ impl ItemScope {
|
|||||||
unresolved,
|
unresolved,
|
||||||
defs,
|
defs,
|
||||||
impls,
|
impls,
|
||||||
|
unnamed_consts,
|
||||||
unnamed_trait_imports,
|
unnamed_trait_imports,
|
||||||
legacy_macros,
|
legacy_macros,
|
||||||
} = self;
|
} = self;
|
||||||
@ -304,6 +310,7 @@ impl ItemScope {
|
|||||||
unresolved.shrink_to_fit();
|
unresolved.shrink_to_fit();
|
||||||
defs.shrink_to_fit();
|
defs.shrink_to_fit();
|
||||||
impls.shrink_to_fit();
|
impls.shrink_to_fit();
|
||||||
|
unnamed_consts.shrink_to_fit();
|
||||||
unnamed_trait_imports.shrink_to_fit();
|
unnamed_trait_imports.shrink_to_fit();
|
||||||
legacy_macros.shrink_to_fit();
|
legacy_macros.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
@ -1163,19 +1163,27 @@ impl ModCollector<'_, '_> {
|
|||||||
}
|
}
|
||||||
ModItem::Const(id) => {
|
ModItem::Const(id) => {
|
||||||
let it = &self.item_tree[id];
|
let it = &self.item_tree[id];
|
||||||
|
let const_id = ConstLoc {
|
||||||
|
container: module.into(),
|
||||||
|
id: ItemTreeId::new(self.file_id, id),
|
||||||
|
}
|
||||||
|
.intern(self.def_collector.db);
|
||||||
|
|
||||||
if let Some(name) = &it.name {
|
match &it.name {
|
||||||
def = Some(DefData {
|
Some(name) => {
|
||||||
id: ConstLoc {
|
def = Some(DefData {
|
||||||
container: module.into(),
|
id: const_id.into(),
|
||||||
id: ItemTreeId::new(self.file_id, id),
|
name,
|
||||||
}
|
visibility: &self.item_tree[it.visibility],
|
||||||
.intern(self.def_collector.db)
|
has_constructor: false,
|
||||||
.into(),
|
});
|
||||||
name,
|
}
|
||||||
visibility: &self.item_tree[it.visibility],
|
None => {
|
||||||
has_constructor: false,
|
// const _: T = ...;
|
||||||
});
|
self.def_collector.def_map.modules[self.module_id]
|
||||||
|
.scope
|
||||||
|
.define_unnamed_const(const_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModItem::Static(id) => {
|
ModItem::Static(id) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user