aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 10:34:41 +0000
committerAleksey Kladov <[email protected]>2019-01-24 10:34:41 +0000
commitf1959bbae0cf2f99e63d074278cec165c274b4e5 (patch)
tree5363a6e6f8a3cc3e2be4fc61340d78def00b70b1
parent3ab1519cb27b927074ed7fbbb18a856e6e7fabb8 (diff)
add FunctionId
-rw-r--r--crates/ra_hir/src/ids.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 99f04e4ef..73f1379f1 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -11,6 +11,7 @@ use crate::{
11pub struct HirInterner { 11pub struct HirInterner {
12 defs: LocationIntener<DefLoc, DefId>, 12 defs: LocationIntener<DefLoc, DefId>,
13 macros: LocationIntener<MacroCallLoc, MacroCallId>, 13 macros: LocationIntener<MacroCallLoc, MacroCallId>,
14 fns: LocationIntener<FunctionLoc, FunctionId>,
14} 15}
15 16
16impl HirInterner { 17impl HirInterner {
@@ -128,6 +129,28 @@ impl MacroCallLoc {
128 } 129 }
129} 130}
130 131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133pub struct FunctionId(RawId);
134impl_arena_id!(FunctionId);
135
136#[derive(Clone, Debug, PartialEq, Eq, Hash)]
137pub struct FunctionLoc {
138 pub(crate) module: Module,
139 pub(crate) source_item_id: SourceItemId,
140}
141
142impl FunctionId {
143 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> FunctionLoc {
144 db.as_ref().fns.id2loc(self)
145 }
146}
147
148impl FunctionLoc {
149 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> FunctionId {
150 db.as_ref().fns.loc2id(&self)
151 }
152}
153
131/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) 154/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
132/// in a specific module. 155/// in a specific module.
133#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 156#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]