diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 87 |
1 files changed, 30 insertions, 57 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 140eccf26..042fd3f8b 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -45,7 +45,7 @@ use std::hash::Hash; | |||
45 | use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; | 45 | use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; |
46 | use ra_arena::{impl_arena_id, RawId}; | 46 | use ra_arena::{impl_arena_id, RawId}; |
47 | use ra_db::{impl_intern_key, salsa, CrateId}; | 47 | use ra_db::{impl_intern_key, salsa, CrateId}; |
48 | use ra_syntax::ast; | 48 | use ra_syntax::{ast, AstNode}; |
49 | 49 | ||
50 | use crate::builtin_type::BuiltinType; | 50 | use crate::builtin_type::BuiltinType; |
51 | 51 | ||
@@ -65,16 +65,23 @@ pub struct ModuleId { | |||
65 | pub struct LocalModuleId(RawId); | 65 | pub struct LocalModuleId(RawId); |
66 | impl_arena_id!(LocalModuleId); | 66 | impl_arena_id!(LocalModuleId); |
67 | 67 | ||
68 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 68 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
69 | pub struct FunctionId(salsa::InternId); | 69 | pub struct ItemLoc<N: AstNode> { |
70 | impl_intern_key!(FunctionId); | 70 | pub container: ContainerId, |
71 | pub ast_id: AstId<N>, | ||
72 | } | ||
71 | 73 | ||
72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 74 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
73 | pub struct FunctionLoc { | 75 | pub struct AssocItemLoc<N: AstNode> { |
74 | pub container: AssocContainerId, | 76 | pub container: AssocContainerId, |
75 | pub ast_id: AstId<ast::FnDef>, | 77 | pub ast_id: AstId<N>, |
76 | } | 78 | } |
77 | 79 | ||
80 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
81 | pub struct FunctionId(salsa::InternId); | ||
82 | impl_intern_key!(FunctionId); | ||
83 | type FunctionLoc = AssocItemLoc<ast::FnDef>; | ||
84 | |||
78 | impl Intern for FunctionLoc { | 85 | impl Intern for FunctionLoc { |
79 | type ID = FunctionId; | 86 | type ID = FunctionId; |
80 | fn intern(self, db: &impl db::DefDatabase) -> FunctionId { | 87 | fn intern(self, db: &impl db::DefDatabase) -> FunctionId { |
@@ -92,12 +99,7 @@ impl Lookup for FunctionId { | |||
92 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 99 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
93 | pub struct StructId(salsa::InternId); | 100 | pub struct StructId(salsa::InternId); |
94 | impl_intern_key!(StructId); | 101 | impl_intern_key!(StructId); |
95 | 102 | pub type StructLoc = ItemLoc<ast::StructDef>; | |
96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
97 | pub struct StructLoc { | ||
98 | pub container: ContainerId, | ||
99 | pub ast_id: AstId<ast::StructDef>, | ||
100 | } | ||
101 | 103 | ||
102 | impl Intern for StructLoc { | 104 | impl Intern for StructLoc { |
103 | type ID = StructId; | 105 | type ID = StructId; |
@@ -116,12 +118,7 @@ impl Lookup for StructId { | |||
116 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 118 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
117 | pub struct UnionId(salsa::InternId); | 119 | pub struct UnionId(salsa::InternId); |
118 | impl_intern_key!(UnionId); | 120 | impl_intern_key!(UnionId); |
119 | 121 | pub type UnionLoc = ItemLoc<ast::UnionDef>; | |
120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
121 | pub struct UnionLoc { | ||
122 | pub container: ContainerId, | ||
123 | pub ast_id: AstId<ast::UnionDef>, | ||
124 | } | ||
125 | 122 | ||
126 | impl Intern for UnionLoc { | 123 | impl Intern for UnionLoc { |
127 | type ID = UnionId; | 124 | type ID = UnionId; |
@@ -140,12 +137,7 @@ impl Lookup for UnionId { | |||
140 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 137 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
141 | pub struct EnumId(salsa::InternId); | 138 | pub struct EnumId(salsa::InternId); |
142 | impl_intern_key!(EnumId); | 139 | impl_intern_key!(EnumId); |
143 | 140 | pub type EnumLoc = ItemLoc<ast::EnumDef>; | |
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
145 | pub struct EnumLoc { | ||
146 | pub container: ContainerId, | ||
147 | pub ast_id: AstId<ast::EnumDef>, | ||
148 | } | ||
149 | 141 | ||
150 | impl Intern for EnumLoc { | 142 | impl Intern for EnumLoc { |
151 | type ID = EnumId; | 143 | type ID = EnumId; |
@@ -185,11 +177,7 @@ impl_arena_id!(LocalStructFieldId); | |||
185 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 177 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
186 | pub struct ConstId(salsa::InternId); | 178 | pub struct ConstId(salsa::InternId); |
187 | impl_intern_key!(ConstId); | 179 | impl_intern_key!(ConstId); |
188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 180 | type ConstLoc = AssocItemLoc<ast::ConstDef>; |
189 | pub struct ConstLoc { | ||
190 | pub container: AssocContainerId, | ||
191 | pub ast_id: AstId<ast::ConstDef>, | ||
192 | } | ||
193 | 181 | ||
194 | impl Intern for ConstLoc { | 182 | impl Intern for ConstLoc { |
195 | type ID = ConstId; | 183 | type ID = ConstId; |
@@ -208,12 +196,7 @@ impl Lookup for ConstId { | |||
208 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 196 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
209 | pub struct StaticId(salsa::InternId); | 197 | pub struct StaticId(salsa::InternId); |
210 | impl_intern_key!(StaticId); | 198 | impl_intern_key!(StaticId); |
211 | 199 | pub type StaticLoc = ItemLoc<ast::StaticDef>; | |
212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
213 | pub struct StaticLoc { | ||
214 | pub container: ContainerId, | ||
215 | pub ast_id: AstId<ast::StaticDef>, | ||
216 | } | ||
217 | 200 | ||
218 | impl Intern for StaticLoc { | 201 | impl Intern for StaticLoc { |
219 | type ID = StaticId; | 202 | type ID = StaticId; |
@@ -232,12 +215,7 @@ impl Lookup for StaticId { | |||
232 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 215 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
233 | pub struct TraitId(salsa::InternId); | 216 | pub struct TraitId(salsa::InternId); |
234 | impl_intern_key!(TraitId); | 217 | impl_intern_key!(TraitId); |
235 | 218 | pub type TraitLoc = ItemLoc<ast::TraitDef>; | |
236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
237 | pub struct TraitLoc { | ||
238 | pub container: ContainerId, | ||
239 | pub ast_id: AstId<ast::TraitDef>, | ||
240 | } | ||
241 | 219 | ||
242 | impl Intern for TraitLoc { | 220 | impl Intern for TraitLoc { |
243 | type ID = TraitId; | 221 | type ID = TraitId; |
@@ -256,12 +234,7 @@ impl Lookup for TraitId { | |||
256 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 234 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
257 | pub struct TypeAliasId(salsa::InternId); | 235 | pub struct TypeAliasId(salsa::InternId); |
258 | impl_intern_key!(TypeAliasId); | 236 | impl_intern_key!(TypeAliasId); |
259 | 237 | type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>; | |
260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
261 | pub struct TypeAliasLoc { | ||
262 | pub container: AssocContainerId, | ||
263 | pub ast_id: AstId<ast::TypeAliasDef>, | ||
264 | } | ||
265 | 238 | ||
266 | impl Intern for TypeAliasLoc { | 239 | impl Intern for TypeAliasLoc { |
267 | type ID = TypeAliasId; | 240 | type ID = TypeAliasId; |
@@ -301,6 +274,16 @@ impl Lookup for ImplId { | |||
301 | } | 274 | } |
302 | } | 275 | } |
303 | 276 | ||
277 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
278 | pub struct TypeParamId { | ||
279 | pub parent: GenericDefId, | ||
280 | pub local_id: LocalTypeParamId, | ||
281 | } | ||
282 | |||
283 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
284 | pub struct LocalTypeParamId(RawId); | ||
285 | impl_arena_id!(LocalTypeParamId); | ||
286 | |||
304 | macro_rules! impl_froms { | 287 | macro_rules! impl_froms { |
305 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { | 288 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { |
306 | $( | 289 | $( |
@@ -321,16 +304,6 @@ macro_rules! impl_froms { | |||
321 | } | 304 | } |
322 | 305 | ||
323 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 306 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
324 | pub struct TypeParamId { | ||
325 | pub parent: GenericDefId, | ||
326 | pub local_id: LocalTypeParamId, | ||
327 | } | ||
328 | |||
329 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
330 | pub struct LocalTypeParamId(RawId); | ||
331 | impl_arena_id!(LocalTypeParamId); | ||
332 | |||
333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
334 | pub enum ContainerId { | 307 | pub enum ContainerId { |
335 | ModuleId(ModuleId), | 308 | ModuleId(ModuleId), |
336 | DefWithBodyId(DefWithBodyId), | 309 | DefWithBodyId(DefWithBodyId), |