diff options
author | Aleksey Kladov <[email protected]> | 2019-11-24 12:13:56 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-24 12:18:12 +0000 |
commit | e0b06cb672b7aae770fea24e4a5efdbec8cbf5c6 (patch) | |
tree | 8623aa0e20f91374ad8d10a6fb1d807274dee5e8 /crates/ra_hir_def/src/lib.rs | |
parent | 982a32aca317deb91ae03346cbc7880bd7d4429b (diff) |
Switch to StaticLoc for statics
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 37 |
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)] |
246 | pub struct StaticId(salsa::InternId); | 246 | pub struct StaticId(salsa::InternId); |
247 | impl_intern_key!(StaticId); | 247 | impl_intern_key!(StaticId); |
248 | impl 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) | 250 | pub struct StaticLoc { |
251 | pub container: ModuleId, | ||
252 | pub ast_id: AstId<ast::StaticDef>, | ||
253 | } | ||
254 | |||
255 | impl 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 | |
262 | impl 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 | ||
496 | impl HasModule for StaticLoc { | ||
497 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { | ||
498 | self.container | ||
499 | } | ||
500 | } | ||
501 | |||
484 | pub trait HasSource { | 502 | pub 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 | ||
534 | impl 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 | |||
516 | pub trait HasChildSource { | 543 | pub trait HasChildSource { |
517 | type ChildId; | 544 | type ChildId; |
518 | type Value; | 545 | type Value; |