]> git.lizzy.rs Git - rust.git/commitdiff
generalize
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 24 Jan 2019 22:05:50 +0000 (01:05 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 24 Jan 2019 22:05:50 +0000 (01:05 +0300)
crates/ra_hir/src/ids.rs

index 9aae58bb63dac566b1d1d12715ef8b53c47f75e5..2cc175bdae130a4fc14b698d5eecd457f2656205 100644 (file)
@@ -1,6 +1,6 @@
 use std::{
     marker::PhantomData,
-    hash::Hash,
+    hash::{Hash, Hasher},
 };
 
 use ra_db::{LocationIntener, FileId};
@@ -139,13 +139,26 @@ pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> MacroCallId {
     }
 }
 
-#[derive(Debug, PartialEq, Eq, Hash)]
+#[derive(Debug)]
 pub struct ItemLoc<N: AstNode> {
     pub(crate) module: Module,
     raw: SourceItemId,
     _ty: PhantomData<N>,
 }
 
+impl<N: AstNode> PartialEq for ItemLoc<N> {
+    fn eq(&self, other: &Self) -> bool {
+        self.module == other.module && self.raw == other.raw
+    }
+}
+impl<N: AstNode> Eq for ItemLoc<N> {}
+impl<N: AstNode> Hash for ItemLoc<N> {
+    fn hash<H: Hasher>(&self, hasher: &mut H) {
+        self.module.hash(hasher);
+        self.raw.hash(hasher);
+    }
+}
+
 impl<N: AstNode> Clone for ItemLoc<N> {
     fn clone(&self) -> ItemLoc<N> {
         ItemLoc {
@@ -173,14 +186,14 @@ pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx
     }
     pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF
     where
-        N: AstNode + Eq + Hash,
+        N: AstNode,
         DEF: AstItemDef<N>,
     {
         DEF::from_ast(self, ast)
     }
 }
 
-pub(crate) trait AstItemDef<N: AstNode + Eq + Hash>: ArenaId + Clone {
+pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
     fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>;
     fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self {
         let items = ctx.db.file_items(ctx.file_id);