diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 |
4 files changed, 38 insertions, 15 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index afd5231cc..0103a1aab 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 | AssocContainerId, DefWithBodyId, FunctionLoc, Intern, | 28 | ContainerId, DefWithBodyId, FunctionLoc, Intern, |
29 | }; | 29 | }; |
30 | 30 | ||
31 | pub(super) fn lower( | 31 | pub(super) fn lower( |
@@ -490,7 +490,7 @@ 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 = AssocContainerId::DefWithBodyId(self.def); | 493 | let container = ContainerId::DefWithBodyId(self.def).into(); |
494 | for item in block.items() { | 494 | for item in block.items() { |
495 | match item { | 495 | match item { |
496 | ast::ModuleItem::FnDef(def) => { | 496 | ast::ModuleItem::FnDef(def) => { |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 3d42762ae..5e46db1aa 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -331,12 +331,18 @@ pub struct LocalTypeParamId(RawId); | |||
331 | impl_arena_id!(LocalTypeParamId); | 331 | impl_arena_id!(LocalTypeParamId); |
332 | 332 | ||
333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
334 | pub enum AssocContainerId { | 334 | pub enum ContainerId { |
335 | ModuleId(ModuleId), | 335 | ModuleId(ModuleId), |
336 | DefWithBodyId(DefWithBodyId), | ||
337 | } | ||
338 | |||
339 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
340 | pub enum AssocContainerId { | ||
341 | ContainerId(ContainerId), | ||
336 | ImplId(ImplId), | 342 | ImplId(ImplId), |
337 | TraitId(TraitId), | 343 | TraitId(TraitId), |
338 | DefWithBodyId(DefWithBodyId), | ||
339 | } | 344 | } |
345 | impl_froms!(AssocContainerId: ContainerId); | ||
340 | 346 | ||
341 | /// A Data Type | 347 | /// A Data Type |
342 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 348 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -479,13 +485,21 @@ pub trait HasModule { | |||
479 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId; | 485 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId; |
480 | } | 486 | } |
481 | 487 | ||
488 | impl HasModule for ContainerId { | ||
489 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | ||
490 | match *self { | ||
491 | ContainerId::ModuleId(it) => it, | ||
492 | ContainerId::DefWithBodyId(it) => it.module(db), | ||
493 | } | ||
494 | } | ||
495 | } | ||
496 | |||
482 | impl HasModule for AssocContainerId { | 497 | impl HasModule for AssocContainerId { |
483 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 498 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
484 | match *self { | 499 | match *self { |
485 | AssocContainerId::ModuleId(it) => it, | 500 | AssocContainerId::ContainerId(it) => it.module(db), |
486 | AssocContainerId::ImplId(it) => it.lookup(db).container, | 501 | AssocContainerId::ImplId(it) => it.lookup(db).container, |
487 | AssocContainerId::TraitId(it) => it.lookup(db).container, | 502 | AssocContainerId::TraitId(it) => it.lookup(db).container, |
488 | AssocContainerId::DefWithBodyId(it) => it.module(db), | ||
489 | } | 503 | } |
490 | } | 504 | } |
491 | } | 505 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 848959f7c..0f3319f30 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | }, | 24 | }, |
25 | path::{ModPath, PathKind}, | 25 | path::{ModPath, PathKind}, |
26 | per_ns::PerNs, | 26 | per_ns::PerNs, |
27 | AdtId, AssocContainerId, AstId, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, | 27 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
28 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, | 28 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, |
29 | TypeAliasLoc, UnionLoc, | 29 | TypeAliasLoc, UnionLoc, |
30 | }; | 30 | }; |
@@ -760,10 +760,11 @@ where | |||
760 | self.collect_derives(attrs, def); | 760 | self.collect_derives(attrs, def); |
761 | 761 | ||
762 | let name = def.name.clone(); | 762 | let name = def.name.clone(); |
763 | let container = ContainerId::ModuleId(module); | ||
763 | let def: PerNs = match def.kind { | 764 | let def: PerNs = match def.kind { |
764 | raw::DefKind::Function(ast_id) => { | 765 | raw::DefKind::Function(ast_id) => { |
765 | let def = FunctionLoc { | 766 | let def = FunctionLoc { |
766 | container: AssocContainerId::ModuleId(module), | 767 | container: container.into(), |
767 | ast_id: AstId::new(self.file_id, ast_id), | 768 | ast_id: AstId::new(self.file_id, ast_id), |
768 | } | 769 | } |
769 | .intern(self.def_collector.db); | 770 | .intern(self.def_collector.db); |
@@ -787,7 +788,7 @@ where | |||
787 | } | 788 | } |
788 | raw::DefKind::Const(ast_id) => { | 789 | raw::DefKind::Const(ast_id) => { |
789 | let def = ConstLoc { | 790 | let def = ConstLoc { |
790 | container: AssocContainerId::ModuleId(module), | 791 | container: container.into(), |
791 | ast_id: AstId::new(self.file_id, ast_id), | 792 | ast_id: AstId::new(self.file_id, ast_id), |
792 | } | 793 | } |
793 | .intern(self.def_collector.db); | 794 | .intern(self.def_collector.db); |
@@ -808,7 +809,7 @@ where | |||
808 | } | 809 | } |
809 | raw::DefKind::TypeAlias(ast_id) => { | 810 | raw::DefKind::TypeAlias(ast_id) => { |
810 | let def = TypeAliasLoc { | 811 | let def = TypeAliasLoc { |
811 | container: AssocContainerId::ModuleId(module), | 812 | container: container.into(), |
812 | ast_id: AstId::new(self.file_id, ast_id), | 813 | ast_id: AstId::new(self.file_id, ast_id), |
813 | } | 814 | } |
814 | .intern(self.def_collector.db); | 815 | .intern(self.def_collector.db); |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index d79c9813b..af9d194f8 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -17,9 +17,9 @@ use crate::{ | |||
17 | nameres::{BuiltinShadowMode, CrateDefMap}, | 17 | nameres::{BuiltinShadowMode, CrateDefMap}, |
18 | path::{ModPath, PathKind}, | 18 | path::{ModPath, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, |
21 | GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, | 21 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, |
22 | StructId, TraitId, TypeAliasId, TypeParamId, VariantId, | 22 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -580,13 +580,21 @@ impl HasResolver for DefWithBodyId { | |||
580 | } | 580 | } |
581 | } | 581 | } |
582 | 582 | ||
583 | impl HasResolver for ContainerId { | ||
584 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
585 | match self { | ||
586 | ContainerId::ModuleId(it) => it.resolver(db), | ||
587 | ContainerId::DefWithBodyId(it) => it.resolver(db), | ||
588 | } | ||
589 | } | ||
590 | } | ||
591 | |||
583 | impl HasResolver for AssocContainerId { | 592 | impl HasResolver for AssocContainerId { |
584 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 593 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
585 | match self { | 594 | match self { |
595 | AssocContainerId::ContainerId(it) => it.resolver(db), | ||
586 | AssocContainerId::TraitId(it) => it.resolver(db), | 596 | AssocContainerId::TraitId(it) => it.resolver(db), |
587 | AssocContainerId::ImplId(it) => it.resolver(db), | 597 | AssocContainerId::ImplId(it) => it.resolver(db), |
588 | AssocContainerId::ModuleId(it) => it.resolver(db), | ||
589 | AssocContainerId::DefWithBodyId(it) => it.resolver(db), | ||
590 | } | 598 | } |
591 | } | 599 | } |
592 | } | 600 | } |