From f04f38d3d79c3cc51956bc530a34e32945cdb294 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 7 Apr 2021 03:12:40 +0200 Subject: nameres: collect unnamed consts --- crates/hir_def/src/nameres/collector.rs | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'crates/hir_def/src/nameres/collector.rs') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index f42f92702..492d8c71f 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1163,19 +1163,27 @@ impl ModCollector<'_, '_> { } ModItem::Const(id) => { let it = &self.item_tree[id]; - - 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, - }); + let const_id = ConstLoc { + container: module.into(), + id: ItemTreeId::new(self.file_id, id), + } + .intern(self.def_collector.db); + + 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) => { -- cgit v1.2.3