diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 36 |
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::{ | |||
13 | pub struct HirInterner { | 13 | pub 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 | ||
21 | impl HirInterner { | 21 | impl HirInterner { |
@@ -182,56 +182,32 @@ impl<N: AstNode> Clone for ItemLoc<N> { | |||
182 | pub struct FunctionId(RawId); | 182 | pub struct FunctionId(RawId); |
183 | impl_arena_id!(FunctionId); | 183 | impl_arena_id!(FunctionId); |
184 | 184 | ||
185 | pub(crate) type FunctionLoc = ItemLoc<ast::FnDef>; | ||
186 | |||
187 | impl FunctionId { | 185 | impl 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 | ||
193 | impl 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)] |
200 | pub struct StructId(RawId); | 192 | pub struct StructId(RawId); |
201 | impl_arena_id!(StructId); | 193 | impl_arena_id!(StructId); |
202 | 194 | ||
203 | pub(crate) type StructLoc = ItemLoc<ast::StructDef>; | ||
204 | |||
205 | impl StructId { | 195 | impl 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 | ||
211 | impl 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)] |
218 | pub struct EnumId(RawId); | 202 | pub struct EnumId(RawId); |
219 | impl_arena_id!(EnumId); | 203 | impl_arena_id!(EnumId); |
220 | 204 | ||
221 | pub(crate) type EnumLoc = ItemLoc<ast::EnumDef>; | ||
222 | |||
223 | impl EnumId { | 205 | impl 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 | ||
229 | impl 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)] |