From 111891dc2dc1d2c7ea87144e8e3ddefe23fc7b6d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Nov 2019 18:00:01 +0300 Subject: Move constants to new ID This allows us to get rid of trait item index --- crates/ra_hir_def/src/lib.rs | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src/lib.rs') 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); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ConstId(salsa::InternId); impl_intern_key!(ConstId); -impl AstItemDef for ConstId { - fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self { - db.intern_const(loc) +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConstLoc { + pub container: ContainerId, + pub ast_id: AstId, +} + +impl Intern for ConstLoc { + type ID = ConstId; + fn intern(self, db: &impl db::DefDatabase2) -> ConstId { + db.intern_const(self) } - fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc { - db.lookup_intern_const(self) +} + +impl Lookup for ConstId { + type Data = ConstLoc; + fn lookup(&self, db: &impl db::DefDatabase2) -> ConstLoc { + db.lookup_intern_const(*self) } } @@ -498,6 +509,16 @@ impl HasModule for TypeAliasLoc { } } +impl HasModule for ConstLoc { + fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { + match self.container { + ContainerId::ModuleId(it) => it, + ContainerId::ImplId(it) => it.module(db), + ContainerId::TraitId(it) => it.module(db), + } + } +} + pub trait HasSource { type Value; fn source(&self, db: &impl db::DefDatabase2) -> Source; @@ -520,3 +541,12 @@ impl HasSource for TypeAliasLoc { Source::new(self.ast_id.file_id(), node) } } + +impl HasSource for ConstLoc { + type Value = ast::ConstDef; + + fn source(&self, db: &impl db::DefDatabase2) -> Source { + let node = self.ast_id.to_node(db); + Source::new(self.ast_id.file_id(), node) + } +} -- cgit v1.2.3