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.rs37
1 files changed, 32 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index b063530c2..89f1ceb58 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -245,12 +245,24 @@ impl Lookup for ConstId {
245#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 245#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
246pub struct StaticId(salsa::InternId); 246pub struct StaticId(salsa::InternId);
247impl_intern_key!(StaticId); 247impl_intern_key!(StaticId);
248impl AstItemDef<ast::StaticDef> for StaticId { 248
249 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StaticDef>) -> Self { 249#[derive(Debug, Clone, PartialEq, Eq, Hash)]
250 db.intern_static(loc) 250pub struct StaticLoc {
251 pub container: ModuleId,
252 pub ast_id: AstId<ast::StaticDef>,
253}
254
255impl Intern for StaticLoc {
256 type ID = StaticId;
257 fn intern(self, db: &impl db::DefDatabase) -> StaticId {
258 db.intern_static(self)
251 } 259 }
252 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StaticDef> { 260}
253 db.lookup_intern_static(self) 261
262impl Lookup for StaticId {
263 type Data = StaticLoc;
264 fn lookup(&self, db: &impl db::DefDatabase) -> StaticLoc {
265 db.lookup_intern_static(*self)
254 } 266 }
255} 267}
256 268
@@ -481,6 +493,12 @@ impl HasModule for ConstLoc {
481 } 493 }
482} 494}
483 495
496impl HasModule for StaticLoc {
497 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
498 self.container
499 }
500}
501
484pub trait HasSource { 502pub trait HasSource {
485 type Value; 503 type Value;
486 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; 504 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>;
@@ -513,6 +531,15 @@ impl HasSource for ConstLoc {
513 } 531 }
514} 532}
515 533
534impl HasSource for StaticLoc {
535 type Value = ast::StaticDef;
536
537 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::StaticDef> {
538 let node = self.ast_id.to_node(db);
539 Source::new(self.ast_id.file_id(), node)
540 }
541}
542
516pub trait HasChildSource { 543pub trait HasChildSource {
517 type ChildId; 544 type ChildId;
518 type Value; 545 type Value;