From fe1b160dcfdeb3f582ccae1440c9580ade0beb39 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:22:55 +0100 Subject: [PATCH] Support for nested statics, consts and type aliases --- crates/ra_hir_def/src/body/lower.rs | 15 ++++++++++++++- crates/ra_hir_def/src/lib.rs | 6 +++--- crates/ra_hir_def/src/nameres/collector.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0d3f946df6..b61f924b77 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,8 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, + ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, + StructLoc, TypeAliasLoc, UnionLoc, }; pub(super) fn lower( @@ -497,6 +498,18 @@ where let ast_id = self.expander.ast_id(&def); FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } + ast::ModuleItem::TypeAliasDef(def) => { + let ast_id = self.expander.ast_id(&def); + TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::ConstDef(def) => { + let ast_id = self.expander.ast_id(&def); + ConstLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::StaticDef(def) => { + let ast_id = self.expander.ast_id(&def); + StaticLoc { container, ast_id }.intern(self.db).into() + } ast::ModuleItem::StructDef(def) => { let ast_id = self.expander.ast_id(&def); StructLoc { container, ast_id }.intern(self.db).into() diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index a82de7dec3..9b192b597a 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -211,7 +211,7 @@ impl_intern_key!(StaticId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StaticLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -558,7 +558,7 @@ impl HasModule for GenericDefId { } impl HasModule for StaticLoc { - fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { - self.container + fn module(&self, db: &impl db::DefDatabase) -> ModuleId { + self.container.module(db) } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 1b39af61e4..74c3d4670d 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -796,7 +796,7 @@ where PerNs::values(def.into()) } raw::DefKind::Static(ast_id) => { - let def = StaticLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = StaticLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::values(def.into())