diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index ada145379c8..4611c6e3867 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs @@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; use crate::{ dyn_map::{DynMap, Policy}, - ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, - TypeAliasId, TypeParamId, EnumId, UnionId, + ConstId, EnumId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, + TypeAliasId, TypeParamId, UnionId, }; type Key = crate::dyn_map::Key, V, AstPtrPolicy>; diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index c9e4e6a0f55..f085bbe872d 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -40,14 +40,14 @@ mod test_db; #[cfg(test)] mod marks; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; -use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId}; +use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; use ra_arena::{impl_arena_id, RawId}; use ra_db::{impl_intern_key, salsa, CrateId}; -use ra_syntax::{ast, AstNode}; +use ra_syntax::ast; -use crate::{builtin_type::BuiltinType, db::InternDatabase}; +use crate::builtin_type::BuiltinType; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct LocalImportId(RawId); @@ -65,63 +65,6 @@ pub struct ModuleId { pub struct LocalModuleId(RawId); impl_arena_id!(LocalModuleId); -#[derive(Debug)] -pub struct ItemLoc { - pub(crate) module: ModuleId, - ast_id: AstId, -} - -impl PartialEq for ItemLoc { - fn eq(&self, other: &Self) -> bool { - self.module == other.module && self.ast_id == other.ast_id - } -} -impl Eq for ItemLoc {} -impl Hash for ItemLoc { - fn hash(&self, hasher: &mut H) { - self.module.hash(hasher); - self.ast_id.hash(hasher); - } -} - -impl Clone for ItemLoc { - fn clone(&self) -> ItemLoc { - ItemLoc { module: self.module, ast_id: self.ast_id } - } -} - -#[derive(Clone, Copy)] -pub struct LocationCtx { - db: DB, - module: ModuleId, - file_id: HirFileId, -} - -impl<'a, DB> LocationCtx<&'a DB> { - pub fn new(db: &'a DB, module: ModuleId, file_id: HirFileId) -> LocationCtx<&'a DB> { - LocationCtx { db, module, file_id } - } -} - -pub trait AstItemDef: salsa::InternKey + Clone { - fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self; - fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc; - - fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId) -> Self { - let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; - Self::intern(ctx.db, loc) - } - fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile { - let loc = self.lookup_intern(db); - let value = loc.ast_id.to_node(db); - InFile { file_id: loc.ast_id.file_id, value } - } - fn module(self, db: &impl InternDatabase) -> ModuleId { - let loc = self.lookup_intern(db); - loc.module - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct FunctionId(salsa::InternId); impl_intern_key!(FunctionId);