]> git.lizzy.rs Git - rust.git/commitdiff
Support for nested statics, consts and type aliases
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 20 Dec 2019 11:22:55 +0000 (12:22 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 20 Dec 2019 11:22:55 +0000 (12:22 +0100)
crates/ra_hir_def/src/body/lower.rs
crates/ra_hir_def/src/lib.rs
crates/ra_hir_def/src/nameres/collector.rs

index 0d3f946df639279d8cf5adbee1e0dbb4bbcd8257..b61f924b778b7250a086ca1131cffba3bcab7cff 100644 (file)
@@ -25,7 +25,8 @@
     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 @@ fn collect_block_items(&mut self, block: &ast::Block) {
                     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()
index a82de7dec3b7561e64af59b84065be391bbe10ee..9b192b597ac7d5deb4142f774ee9a10adab1d324 100644 (file)
@@ -211,7 +211,7 @@ fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc {
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub struct StaticLoc {
-    pub container: ModuleId,
+    pub container: ContainerId,
     pub ast_id: AstId<ast::StaticDef>,
 }
 
@@ -558,7 +558,7 @@ fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
 }
 
 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)
     }
 }
index 1b39af61e4c12715fba06b460d19b91ba3b062d6..74c3d4670d7fed2fe13b16511d289cec2b256bcc 100644 (file)
@@ -796,7 +796,7 @@ fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) {
                 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())