aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-20 15:00:01 +0000
committerAleksey Kladov <[email protected]>2019-11-20 15:41:23 +0000
commit111891dc2dc1d2c7ea87144e8e3ddefe23fc7b6d (patch)
tree7e96d773620a3b03254d00386711cdc7c909e3ee /crates/ra_hir_def/src/lib.rs
parentee95a35664e6fe9153f6324cfc57872ca365887c (diff)
Move constants to new ID
This allows us to get rid of trait item index
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs40
1 files changed, 35 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index da6506fcd..0af41de87 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -289,12 +289,23 @@ impl_arena_id!(LocalStructFieldId);
289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
290pub struct ConstId(salsa::InternId); 290pub struct ConstId(salsa::InternId);
291impl_intern_key!(ConstId); 291impl_intern_key!(ConstId);
292impl AstItemDef<ast::ConstDef> for ConstId { 292#[derive(Debug, Clone, PartialEq, Eq, Hash)]
293 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ConstDef>) -> Self { 293pub struct ConstLoc {
294 db.intern_const(loc) 294 pub container: ContainerId,
295 pub ast_id: AstId<ast::ConstDef>,
296}
297
298impl Intern for ConstLoc {
299 type ID = ConstId;
300 fn intern(self, db: &impl db::DefDatabase2) -> ConstId {
301 db.intern_const(self)
295 } 302 }
296 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ConstDef> { 303}
297 db.lookup_intern_const(self) 304
305impl Lookup for ConstId {
306 type Data = ConstLoc;
307 fn lookup(&self, db: &impl db::DefDatabase2) -> ConstLoc {
308 db.lookup_intern_const(*self)
298 } 309 }
299} 310}
300 311
@@ -498,6 +509,16 @@ impl HasModule for TypeAliasLoc {
498 } 509 }
499} 510}
500 511
512impl HasModule for ConstLoc {
513 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
514 match self.container {
515 ContainerId::ModuleId(it) => it,
516 ContainerId::ImplId(it) => it.module(db),
517 ContainerId::TraitId(it) => it.module(db),
518 }
519 }
520}
521
501pub trait HasSource { 522pub trait HasSource {
502 type Value; 523 type Value;
503 fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; 524 fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>;
@@ -520,3 +541,12 @@ impl HasSource for TypeAliasLoc {
520 Source::new(self.ast_id.file_id(), node) 541 Source::new(self.ast_id.file_id(), node)
521 } 542 }
522} 543}
544
545impl HasSource for ConstLoc {
546 type Value = ast::ConstDef;
547
548 fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::ConstDef> {
549 let node = self.ast_id.to_node(db);
550 Source::new(self.ast_id.file_id(), node)
551 }
552}