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 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,
|
||||
};
|
||||
|
||||
@ -37,6 +37,7 @@ pub struct ItemScope {
|
||||
|
||||
defs: Vec<ModuleDefId>,
|
||||
impls: Vec<ImplId>,
|
||||
unnamed_consts: Vec<ConstId>,
|
||||
/// Traits imported via `use Trait as _;`.
|
||||
unnamed_trait_imports: FxHashMap<TraitId, Visibility>,
|
||||
/// Macros visible in current module in legacy textual scope
|
||||
@ -156,6 +157,10 @@ impl ItemScope {
|
||||
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) {
|
||||
self.legacy_macros.insert(name, mac);
|
||||
}
|
||||
@ -295,6 +300,7 @@ impl ItemScope {
|
||||
unresolved,
|
||||
defs,
|
||||
impls,
|
||||
unnamed_consts,
|
||||
unnamed_trait_imports,
|
||||
legacy_macros,
|
||||
} = self;
|
||||
@ -304,6 +310,7 @@ impl ItemScope {
|
||||
unresolved.shrink_to_fit();
|
||||
defs.shrink_to_fit();
|
||||
impls.shrink_to_fit();
|
||||
unnamed_consts.shrink_to_fit();
|
||||
unnamed_trait_imports.shrink_to_fit();
|
||||
legacy_macros.shrink_to_fit();
|
||||
}
|
||||
|
@ -1163,19 +1163,27 @@ impl ModCollector<'_, '_> {
|
||||
}
|
||||
ModItem::Const(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 {
|
||||
def = Some(DefData {
|
||||
id: ConstLoc {
|
||||
container: module.into(),
|
||||
id: ItemTreeId::new(self.file_id, id),
|
||||
}
|
||||
.intern(self.def_collector.db)
|
||||
.into(),
|
||||
name,
|
||||
visibility: &self.item_tree[it.visibility],
|
||||
has_constructor: false,
|
||||
});
|
||||
match &it.name {
|
||||
Some(name) => {
|
||||
def = Some(DefData {
|
||||
id: const_id.into(),
|
||||
name,
|
||||
visibility: &self.item_tree[it.visibility],
|
||||
has_constructor: false,
|
||||
});
|
||||
}
|
||||
None => {
|
||||
// const _: T = ...;
|
||||
self.def_collector.def_map.modules[self.module_id]
|
||||
.scope
|
||||
.define_unnamed_const(const_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
ModItem::Static(id) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user