aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ids.rs21
1 files 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 @@
1use std::{ 1use std::{
2 marker::PhantomData, 2 marker::PhantomData,
3 hash::Hash, 3 hash::{Hash, Hasher},
4}; 4};
5 5
6use ra_db::{LocationIntener, FileId}; 6use ra_db::{LocationIntener, FileId};
@@ -139,13 +139,26 @@ impl MacroCallLoc {
139 } 139 }
140} 140}
141 141
142#[derive(Debug, PartialEq, Eq, Hash)] 142#[derive(Debug)]
143pub struct ItemLoc<N: AstNode> { 143pub struct ItemLoc<N: AstNode> {
144 pub(crate) module: Module, 144 pub(crate) module: Module,
145 raw: SourceItemId, 145 raw: SourceItemId,
146 _ty: PhantomData<N>, 146 _ty: PhantomData<N>,
147} 147}
148 148
149impl<N: AstNode> PartialEq for ItemLoc<N> {
150 fn eq(&self, other: &Self) -> bool {
151 self.module == other.module && self.raw == other.raw
152 }
153}
154impl<N: AstNode> Eq for ItemLoc<N> {}
155impl<N: AstNode> Hash for ItemLoc<N> {
156 fn hash<H: Hasher>(&self, hasher: &mut H) {
157 self.module.hash(hasher);
158 self.raw.hash(hasher);
159 }
160}
161
149impl<N: AstNode> Clone for ItemLoc<N> { 162impl<N: AstNode> Clone for ItemLoc<N> {
150 fn clone(&self) -> ItemLoc<N> { 163 fn clone(&self) -> ItemLoc<N> {
151 ItemLoc { 164 ItemLoc {
@@ -173,14 +186,14 @@ impl<'a, DB: HirDatabase> LocationCtx<&'a DB> {
173 } 186 }
174 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF 187 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF
175 where 188 where
176 N: AstNode + Eq + Hash, 189 N: AstNode,
177 DEF: AstItemDef<N>, 190 DEF: AstItemDef<N>,
178 { 191 {
179 DEF::from_ast(self, ast) 192 DEF::from_ast(self, ast)
180 } 193 }
181} 194}
182 195
183pub(crate) trait AstItemDef<N: AstNode + Eq + Hash>: ArenaId + Clone { 196pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
184 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>; 197 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>;
185 fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self { 198 fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self {
186 let items = ctx.db.file_items(ctx.file_id); 199 let items = ctx.db.file_items(ctx.file_id);