diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 6 |
3 files changed, 27 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0103a1aab..0d3f946df 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -25,7 +25,7 @@ use crate::{ | |||
25 | path::GenericArgs, | 25 | path::GenericArgs, |
26 | path::Path, | 26 | path::Path, |
27 | type_ref::{Mutability, TypeRef}, | 27 | type_ref::{Mutability, TypeRef}, |
28 | ContainerId, DefWithBodyId, FunctionLoc, Intern, | 28 | ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, |
29 | }; | 29 | }; |
30 | 30 | ||
31 | pub(super) fn lower( | 31 | pub(super) fn lower( |
@@ -490,16 +490,28 @@ where | |||
490 | } | 490 | } |
491 | 491 | ||
492 | fn collect_block_items(&mut self, block: &ast::Block) { | 492 | fn collect_block_items(&mut self, block: &ast::Block) { |
493 | let container = ContainerId::DefWithBodyId(self.def).into(); | 493 | let container = ContainerId::DefWithBodyId(self.def); |
494 | for item in block.items() { | 494 | for item in block.items() { |
495 | match item { | 495 | let def: ModuleDefId = match item { |
496 | ast::ModuleItem::FnDef(def) => { | 496 | ast::ModuleItem::FnDef(def) => { |
497 | let ast_id = self.expander.ast_id(&def); | 497 | let ast_id = self.expander.ast_id(&def); |
498 | self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) | 498 | FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() |
499 | } | 499 | } |
500 | // FIXME: handle other items | 500 | ast::ModuleItem::StructDef(def) => { |
501 | _ => (), | 501 | let ast_id = self.expander.ast_id(&def); |
502 | } | 502 | StructLoc { container, ast_id }.intern(self.db).into() |
503 | } | ||
504 | ast::ModuleItem::EnumDef(def) => { | ||
505 | let ast_id = self.expander.ast_id(&def); | ||
506 | EnumLoc { container, ast_id }.intern(self.db).into() | ||
507 | } | ||
508 | ast::ModuleItem::UnionDef(def) => { | ||
509 | let ast_id = self.expander.ast_id(&def); | ||
510 | UnionLoc { container, ast_id }.intern(self.db).into() | ||
511 | } | ||
512 | _ => continue, | ||
513 | }; | ||
514 | self.body.defs.push(def) | ||
503 | } | 515 | } |
504 | } | 516 | } |
505 | 517 | ||
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 5e46db1aa..a82de7dec 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -95,7 +95,7 @@ impl_intern_key!(StructId); | |||
95 | 95 | ||
96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
97 | pub struct StructLoc { | 97 | pub struct StructLoc { |
98 | pub container: ModuleId, | 98 | pub container: ContainerId, |
99 | pub ast_id: AstId<ast::StructDef>, | 99 | pub ast_id: AstId<ast::StructDef>, |
100 | } | 100 | } |
101 | 101 | ||
@@ -119,7 +119,7 @@ impl_intern_key!(UnionId); | |||
119 | 119 | ||
120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
121 | pub struct UnionLoc { | 121 | pub struct UnionLoc { |
122 | pub container: ModuleId, | 122 | pub container: ContainerId, |
123 | pub ast_id: AstId<ast::UnionDef>, | 123 | pub ast_id: AstId<ast::UnionDef>, |
124 | } | 124 | } |
125 | 125 | ||
@@ -143,7 +143,7 @@ impl_intern_key!(EnumId); | |||
143 | 143 | ||
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
145 | pub struct EnumLoc { | 145 | pub struct EnumLoc { |
146 | pub container: ModuleId, | 146 | pub container: ContainerId, |
147 | pub ast_id: AstId<ast::EnumDef>, | 147 | pub ast_id: AstId<ast::EnumDef>, |
148 | } | 148 | } |
149 | 149 | ||
@@ -529,6 +529,7 @@ impl HasModule for AdtId { | |||
529 | AdtId::UnionId(it) => it.lookup(db).container, | 529 | AdtId::UnionId(it) => it.lookup(db).container, |
530 | AdtId::EnumId(it) => it.lookup(db).container, | 530 | AdtId::EnumId(it) => it.lookup(db).container, |
531 | } | 531 | } |
532 | .module(db) | ||
532 | } | 533 | } |
533 | } | 534 | } |
534 | 535 | ||
@@ -550,7 +551,7 @@ impl HasModule for GenericDefId { | |||
550 | GenericDefId::TraitId(it) => it.lookup(db).container, | 551 | GenericDefId::TraitId(it) => it.lookup(db).container, |
551 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), | 552 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), |
552 | GenericDefId::ImplId(it) => it.lookup(db).container, | 553 | GenericDefId::ImplId(it) => it.lookup(db).container, |
553 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, | 554 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), |
554 | GenericDefId::ConstId(it) => it.lookup(db).module(db), | 555 | GenericDefId::ConstId(it) => it.lookup(db).module(db), |
555 | } | 556 | } |
556 | } | 557 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 0f3319f30..1b39af61e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -772,17 +772,17 @@ where | |||
772 | PerNs::values(def.into()) | 772 | PerNs::values(def.into()) |
773 | } | 773 | } |
774 | raw::DefKind::Struct(ast_id) => { | 774 | raw::DefKind::Struct(ast_id) => { |
775 | let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 775 | let def = StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
776 | .intern(self.def_collector.db); | 776 | .intern(self.def_collector.db); |
777 | PerNs::both(def.into(), def.into()) | 777 | PerNs::both(def.into(), def.into()) |
778 | } | 778 | } |
779 | raw::DefKind::Union(ast_id) => { | 779 | raw::DefKind::Union(ast_id) => { |
780 | let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 780 | let def = UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
781 | .intern(self.def_collector.db); | 781 | .intern(self.def_collector.db); |
782 | PerNs::both(def.into(), def.into()) | 782 | PerNs::both(def.into(), def.into()) |
783 | } | 783 | } |
784 | raw::DefKind::Enum(ast_id) => { | 784 | raw::DefKind::Enum(ast_id) => { |
785 | let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 785 | let def = EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
786 | .intern(self.def_collector.db); | 786 | .intern(self.def_collector.db); |
787 | PerNs::types(def.into()) | 787 | PerNs::types(def.into()) |
788 | } | 788 | } |