aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/adt.rs10
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs6
-rw-r--r--crates/ra_hir/src/ids.rs36
3 files changed, 14 insertions, 38 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index baf853a3a..17ece93a7 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -13,7 +13,7 @@ use crate::{
13 HirDatabase, DefKind, 13 HirDatabase, DefKind,
14 SourceItemId, 14 SourceItemId,
15 type_ref::TypeRef, 15 type_ref::TypeRef,
16 ids::{StructLoc, EnumLoc}, 16 ids::ItemLoc,
17}; 17};
18 18
19impl Struct { 19impl Struct {
@@ -23,8 +23,8 @@ impl Struct {
23 file_id: HirFileId, 23 file_id: HirFileId,
24 ast: &ast::StructDef, 24 ast: &ast::StructDef,
25 ) -> Struct { 25 ) -> Struct {
26 let loc: StructLoc = StructLoc::from_ast(db, module, file_id, ast); 26 let loc = ItemLoc::from_ast(db, module, file_id, ast);
27 let id = loc.id(db); 27 let id = db.as_ref().structs.loc2id(&loc);
28 Struct { id } 28 Struct { id }
29 } 29 }
30 30
@@ -40,8 +40,8 @@ impl Enum {
40 file_id: HirFileId, 40 file_id: HirFileId,
41 ast: &ast::EnumDef, 41 ast: &ast::EnumDef,
42 ) -> Enum { 42 ) -> Enum {
43 let loc: EnumLoc = EnumLoc::from_ast(db, module, file_id, ast); 43 let loc = ItemLoc::from_ast(db, module, file_id, ast);
44 let id = loc.id(db); 44 let id = db.as_ref().enums.loc2id(&loc);
45 Enum { id } 45 Enum { id }
46 } 46 }
47} 47}
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index d8dafb10e..8a2ab5714 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -9,7 +9,7 @@ use crate::{
9 type_ref::{TypeRef, Mutability}, 9 type_ref::{TypeRef, Mutability},
10 expr::Body, 10 expr::Body,
11 impl_block::ImplBlock, 11 impl_block::ImplBlock,
12 ids::FunctionLoc, 12 ids::ItemLoc,
13}; 13};
14 14
15pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; 15pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax};
@@ -21,8 +21,8 @@ impl Function {
21 file_id: HirFileId, 21 file_id: HirFileId,
22 ast: &ast::FnDef, 22 ast: &ast::FnDef,
23 ) -> Function { 23 ) -> Function {
24 let loc: FunctionLoc = FunctionLoc::from_ast(db, module, file_id, ast); 24 let loc = ItemLoc::from_ast(db, module, file_id, ast);
25 let id = loc.id(db); 25 let id = db.as_ref().fns.loc2id(&loc);
26 Function { id } 26 Function { id }
27 } 27 }
28 28
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)]