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/traits.rs | 45 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) (limited to 'crates/ra_hir_def/src/traits.rs') diff --git a/crates/ra_hir_def/src/traits.rs b/crates/ra_hir_def/src/traits.rs index bb61e852a..877d73d66 100644 --- a/crates/ra_hir_def/src/traits.rs +++ b/crates/ra_hir_def/src/traits.rs @@ -8,11 +8,10 @@ use hir_expand::{ }; use ra_syntax::ast::{self, NameOwner}; -use rustc_hash::FxHashMap; use crate::{ - db::DefDatabase2, AssocItemId, AstItemDef, ConstId, ContainerId, FunctionLoc, Intern, - LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasLoc, + db::DefDatabase2, AssocItemId, AstItemDef, ConstLoc, ContainerId, FunctionLoc, Intern, TraitId, + TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -26,8 +25,6 @@ impl TraitData { pub(crate) fn trait_data_query(db: &impl DefDatabase2, tr: TraitId) -> Arc { let src = tr.source(db); let name = src.value.name().map(|n| n.as_name()); - let module = tr.module(db); - let ctx = LocationCtx::new(db, module, src.file_id); let auto = src.value.is_auto(); let ast_id_map = db.ast_id_map(src.file_id); let items = if let Some(item_list) = src.value.item_list() { @@ -40,7 +37,12 @@ impl TraitData { } .intern(db) .into(), - ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), + ast::ImplItem::ConstDef(it) => ConstLoc { + container: ContainerId::TraitId(tr), + ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), + } + .intern(db) + .into(), ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { container: ContainerId::TraitId(tr), ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), @@ -55,34 +57,3 @@ impl TraitData { Arc::new(TraitData { name, items, auto }) } } - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct TraitItemsIndex { - traits_by_def: FxHashMap, -} - -impl TraitItemsIndex { - pub fn trait_items_index(db: &impl DefDatabase2, module: ModuleId) -> TraitItemsIndex { - let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() }; - let crate_def_map = db.crate_def_map(module.krate); - for decl in crate_def_map[module.module_id].scope.declarations() { - if let ModuleDefId::TraitId(tr) = decl { - for item in db.trait_data(tr).items.iter() { - match item { - AssocItemId::FunctionId(_) => (), - AssocItemId::TypeAliasId(_) => (), - _ => { - let prev = index.traits_by_def.insert(*item, tr); - assert!(prev.is_none()); - } - } - } - } - } - index - } - - pub fn get_parent_trait(&self, item: AssocItemId) -> Option { - self.traits_by_def.get(&item).cloned() - } -} -- cgit v1.2.3