aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs36
1 files changed, 6 insertions, 30 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 332cec9c8..6375c76c9 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -13,9 +13,9 @@ use crate::{
13pub struct HirInterner { 13pub struct HirInterner {
14 defs: LocationIntener<DefLoc, DefId>, 14 defs: LocationIntener<DefLoc, DefId>,
15 macros: LocationIntener<MacroCallLoc, MacroCallId>, 15 macros: LocationIntener<MacroCallLoc, MacroCallId>,
16 fns: LocationIntener<FunctionLoc, FunctionId>, 16 pub(crate) fns: LocationIntener<ItemLoc<ast::FnDef>, FunctionId>,
17 structs: LocationIntener<StructLoc, StructId>, 17 pub(crate) structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>,
18 enums: LocationIntener<EnumLoc, EnumId>, 18 pub(crate) enums: LocationIntener<ItemLoc<ast::EnumDef>, EnumId>,
19} 19}
20 20
21impl HirInterner { 21impl HirInterner {
@@ -182,56 +182,32 @@ impl<N: AstNode> Clone for ItemLoc<N> {
182pub struct FunctionId(RawId); 182pub struct FunctionId(RawId);
183impl_arena_id!(FunctionId); 183impl_arena_id!(FunctionId);
184 184
185pub(crate) type FunctionLoc = ItemLoc<ast::FnDef>;
186
187impl FunctionId { 185impl FunctionId {
188 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> FunctionLoc { 186 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> ItemLoc<ast::FnDef> {
189 db.as_ref().fns.id2loc(self) 187 db.as_ref().fns.id2loc(self)
190 } 188 }
191} 189}
192 190
193impl FunctionLoc {
194 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> FunctionId {
195 db.as_ref().fns.loc2id(&self)
196 }
197}
198
199#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 191#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
200pub struct StructId(RawId); 192pub struct StructId(RawId);
201impl_arena_id!(StructId); 193impl_arena_id!(StructId);
202 194
203pub(crate) type StructLoc = ItemLoc<ast::StructDef>;
204
205impl StructId { 195impl StructId {
206 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> StructLoc { 196 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> ItemLoc<ast::StructDef> {
207 db.as_ref().structs.id2loc(self) 197 db.as_ref().structs.id2loc(self)
208 } 198 }
209} 199}
210 200
211impl StructLoc {
212 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> StructId {
213 db.as_ref().structs.loc2id(&self)
214 }
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 201#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
218pub struct EnumId(RawId); 202pub struct EnumId(RawId);
219impl_arena_id!(EnumId); 203impl_arena_id!(EnumId);
220 204
221pub(crate) type EnumLoc = ItemLoc<ast::EnumDef>;
222
223impl EnumId { 205impl EnumId {
224 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> EnumLoc { 206 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> ItemLoc<ast::EnumDef> {
225 db.as_ref().enums.id2loc(self) 207 db.as_ref().enums.id2loc(self)
226 } 208 }
227} 209}
228 210
229impl EnumLoc {
230 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> EnumId {
231 db.as_ref().enums.loc2id(&self)
232 }
233}
234
235/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) 211/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
236/// in a specific module. 212/// in a specific module.
237#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 213#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]