diff options
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 4fc3127c4..140eccf26 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -71,7 +71,7 @@ impl_intern_key!(FunctionId); | |||
71 | 71 | ||
72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
73 | pub struct FunctionLoc { | 73 | pub struct FunctionLoc { |
74 | pub container: ContainerId, | 74 | pub container: AssocContainerId, |
75 | pub ast_id: AstId<ast::FnDef>, | 75 | pub ast_id: AstId<ast::FnDef>, |
76 | } | 76 | } |
77 | 77 | ||
@@ -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 | ||
@@ -187,7 +187,7 @@ pub struct ConstId(salsa::InternId); | |||
187 | impl_intern_key!(ConstId); | 187 | impl_intern_key!(ConstId); |
188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
189 | pub struct ConstLoc { | 189 | pub struct ConstLoc { |
190 | pub container: ContainerId, | 190 | pub container: AssocContainerId, |
191 | pub ast_id: AstId<ast::ConstDef>, | 191 | pub ast_id: AstId<ast::ConstDef>, |
192 | } | 192 | } |
193 | 193 | ||
@@ -211,7 +211,7 @@ impl_intern_key!(StaticId); | |||
211 | 211 | ||
212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
213 | pub struct StaticLoc { | 213 | pub struct StaticLoc { |
214 | pub container: ModuleId, | 214 | pub container: ContainerId, |
215 | pub ast_id: AstId<ast::StaticDef>, | 215 | pub ast_id: AstId<ast::StaticDef>, |
216 | } | 216 | } |
217 | 217 | ||
@@ -235,7 +235,7 @@ impl_intern_key!(TraitId); | |||
235 | 235 | ||
236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
237 | pub struct TraitLoc { | 237 | pub struct TraitLoc { |
238 | pub container: ModuleId, | 238 | pub container: ContainerId, |
239 | pub ast_id: AstId<ast::TraitDef>, | 239 | pub ast_id: AstId<ast::TraitDef>, |
240 | } | 240 | } |
241 | 241 | ||
@@ -259,7 +259,7 @@ impl_intern_key!(TypeAliasId); | |||
259 | 259 | ||
260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
261 | pub struct TypeAliasLoc { | 261 | pub struct TypeAliasLoc { |
262 | pub container: ContainerId, | 262 | pub container: AssocContainerId, |
263 | pub ast_id: AstId<ast::TypeAliasDef>, | 263 | pub ast_id: AstId<ast::TypeAliasDef>, |
264 | } | 264 | } |
265 | 265 | ||
@@ -333,10 +333,16 @@ impl_arena_id!(LocalTypeParamId); | |||
333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
334 | pub enum ContainerId { | 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)] |
@@ -483,13 +489,21 @@ impl HasModule for ContainerId { | |||
483 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 489 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
484 | match *self { | 490 | match *self { |
485 | ContainerId::ModuleId(it) => it, | 491 | ContainerId::ModuleId(it) => it, |
486 | ContainerId::ImplId(it) => it.lookup(db).container, | ||
487 | ContainerId::TraitId(it) => it.lookup(db).container, | ||
488 | ContainerId::DefWithBodyId(it) => it.module(db), | 492 | ContainerId::DefWithBodyId(it) => it.module(db), |
489 | } | 493 | } |
490 | } | 494 | } |
491 | } | 495 | } |
492 | 496 | ||
497 | impl HasModule for AssocContainerId { | ||
498 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | ||
499 | match *self { | ||
500 | AssocContainerId::ContainerId(it) => it.module(db), | ||
501 | AssocContainerId::ImplId(it) => it.lookup(db).container, | ||
502 | AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | |||
493 | impl HasModule for FunctionLoc { | 507 | impl HasModule for FunctionLoc { |
494 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 508 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
495 | self.container.module(db) | 509 | self.container.module(db) |
@@ -515,6 +529,7 @@ impl HasModule for AdtId { | |||
515 | AdtId::UnionId(it) => it.lookup(db).container, | 529 | AdtId::UnionId(it) => it.lookup(db).container, |
516 | AdtId::EnumId(it) => it.lookup(db).container, | 530 | AdtId::EnumId(it) => it.lookup(db).container, |
517 | } | 531 | } |
532 | .module(db) | ||
518 | } | 533 | } |
519 | } | 534 | } |
520 | 535 | ||
@@ -533,17 +548,17 @@ impl HasModule for GenericDefId { | |||
533 | match self { | 548 | match self { |
534 | GenericDefId::FunctionId(it) => it.lookup(db).module(db), | 549 | GenericDefId::FunctionId(it) => it.lookup(db).module(db), |
535 | GenericDefId::AdtId(it) => it.module(db), | 550 | GenericDefId::AdtId(it) => it.module(db), |
536 | GenericDefId::TraitId(it) => it.lookup(db).container, | 551 | GenericDefId::TraitId(it) => it.lookup(db).container.module(db), |
537 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), | 552 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), |
538 | GenericDefId::ImplId(it) => it.lookup(db).container, | 553 | GenericDefId::ImplId(it) => it.lookup(db).container, |
539 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, | 554 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), |
540 | GenericDefId::ConstId(it) => it.lookup(db).module(db), | 555 | GenericDefId::ConstId(it) => it.lookup(db).module(db), |
541 | } | 556 | } |
542 | } | 557 | } |
543 | } | 558 | } |
544 | 559 | ||
545 | impl HasModule for StaticLoc { | 560 | impl HasModule for StaticLoc { |
546 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { | 561 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
547 | self.container | 562 | self.container.module(db) |
548 | } | 563 | } |
549 | } | 564 | } |