From 00ba70a0957b8af2813940787238a733298dfa5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 01:05:50 +0300 Subject: generalize --- crates/ra_hir/src/ids.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 9aae58bb6..2cc175bda 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -1,6 +1,6 @@ use std::{ marker::PhantomData, - hash::Hash, + hash::{Hash, Hasher}, }; use ra_db::{LocationIntener, FileId}; @@ -139,13 +139,26 @@ impl MacroCallLoc { } } -#[derive(Debug, PartialEq, Eq, Hash)] +#[derive(Debug)] pub struct ItemLoc { pub(crate) module: Module, raw: SourceItemId, _ty: PhantomData, } +impl PartialEq for ItemLoc { + fn eq(&self, other: &Self) -> bool { + self.module == other.module && self.raw == other.raw + } +} +impl Eq for ItemLoc {} +impl Hash for ItemLoc { + fn hash(&self, hasher: &mut H) { + self.module.hash(hasher); + self.raw.hash(hasher); + } +} + impl Clone for ItemLoc { fn clone(&self) -> ItemLoc { ItemLoc { @@ -173,14 +186,14 @@ impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { } pub(crate) fn to_def(self, ast: &N) -> DEF where - N: AstNode + Eq + Hash, + N: AstNode, DEF: AstItemDef, { DEF::from_ast(self, ast) } } -pub(crate) trait AstItemDef: ArenaId + Clone { +pub(crate) trait AstItemDef: ArenaId + Clone { fn interner(interner: &HirInterner) -> &LocationIntener, Self>; fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self { let items = ctx.db.file_items(ctx.file_id); -- cgit v1.2.3