aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 569da4f28..5564b166b 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -289,12 +289,24 @@ impl Lookup for TypeAliasId {
289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
290pub struct ImplId(salsa::InternId); 290pub struct ImplId(salsa::InternId);
291impl_intern_key!(ImplId); 291impl_intern_key!(ImplId);
292impl AstItemDef<ast::ImplBlock> for ImplId { 292
293 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ImplBlock>) -> Self { 293#[derive(Debug, Clone, PartialEq, Eq, Hash)]
294 db.intern_impl(loc) 294pub struct ImplLoc {
295 pub container: ModuleId,
296 pub ast_id: AstId<ast::ImplBlock>,
297}
298
299impl Intern for ImplLoc {
300 type ID = ImplId;
301 fn intern(self, db: &impl db::DefDatabase) -> ImplId {
302 db.intern_impl(self)
295 } 303 }
296 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ImplBlock> { 304}
297 db.lookup_intern_impl(self) 305
306impl Lookup for ImplId {
307 type Data = ImplLoc;
308 fn lookup(&self, db: &impl db::DefDatabase) -> ImplLoc {
309 db.lookup_intern_impl(*self)
298 } 310 }
299} 311}
300 312
@@ -479,7 +491,7 @@ impl HasModule for FunctionLoc {
479 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 491 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
480 match self.container { 492 match self.container {
481 ContainerId::ModuleId(it) => it, 493 ContainerId::ModuleId(it) => it,
482 ContainerId::ImplId(it) => it.module(db), 494 ContainerId::ImplId(it) => it.lookup(db).container,
483 ContainerId::TraitId(it) => it.module(db), 495 ContainerId::TraitId(it) => it.module(db),
484 } 496 }
485 } 497 }
@@ -489,7 +501,7 @@ impl HasModule for TypeAliasLoc {
489 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 501 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
490 match self.container { 502 match self.container {
491 ContainerId::ModuleId(it) => it, 503 ContainerId::ModuleId(it) => it,
492 ContainerId::ImplId(it) => it.module(db), 504 ContainerId::ImplId(it) => it.lookup(db).container,
493 ContainerId::TraitId(it) => it.module(db), 505 ContainerId::TraitId(it) => it.module(db),
494 } 506 }
495 } 507 }
@@ -499,7 +511,7 @@ impl HasModule for ConstLoc {
499 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 511 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
500 match self.container { 512 match self.container {
501 ContainerId::ModuleId(it) => it, 513 ContainerId::ModuleId(it) => it,
502 ContainerId::ImplId(it) => it.module(db), 514 ContainerId::ImplId(it) => it.lookup(db).container,
503 ContainerId::TraitId(it) => it.module(db), 515 ContainerId::TraitId(it) => it.module(db),
504 } 516 }
505 } 517 }
@@ -532,7 +544,7 @@ impl HasModule for GenericDefId {
532 GenericDefId::AdtId(it) => it.module(db), 544 GenericDefId::AdtId(it) => it.module(db),
533 GenericDefId::TraitId(it) => it.module(db), 545 GenericDefId::TraitId(it) => it.module(db),
534 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 546 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
535 GenericDefId::ImplId(it) => it.module(db), 547 GenericDefId::ImplId(it) => it.lookup(db).container,
536 GenericDefId::EnumVariantId(it) => it.parent.module(db), 548 GenericDefId::EnumVariantId(it) => it.parent.module(db),
537 GenericDefId::ConstId(it) => it.lookup(db).module(db), 549 GenericDefId::ConstId(it) => it.lookup(db).module(db),
538 } 550 }