aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 12:11:01 +0000
committerAleksey Kladov <[email protected]>2019-12-20 12:11:01 +0000
commit957c0171e63631f67d732f4ce53dc8bfe2602e71 (patch)
tree6503fb74cbcf61b92f40db42f8fb889771647c4d
parent65377620245bda207145742595a7bd878e14f7ec (diff)
Remove more copy-paste
-rw-r--r--crates/ra_hir_def/src/lib.rs87
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;
45use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; 45use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId};
46use ra_arena::{impl_arena_id, RawId}; 46use ra_arena::{impl_arena_id, RawId};
47use ra_db::{impl_intern_key, salsa, CrateId}; 47use ra_db::{impl_intern_key, salsa, CrateId};
48use ra_syntax::ast; 48use ra_syntax::{ast, AstNode};
49 49
50use crate::builtin_type::BuiltinType; 50use crate::builtin_type::BuiltinType;
51 51
@@ -65,16 +65,23 @@ pub struct ModuleId {
65pub struct LocalModuleId(RawId); 65pub struct LocalModuleId(RawId);
66impl_arena_id!(LocalModuleId); 66impl_arena_id!(LocalModuleId);
67 67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 68#[derive(Debug, Clone, PartialEq, Eq, Hash)]
69pub struct FunctionId(salsa::InternId); 69pub struct ItemLoc<N: AstNode> {
70impl_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)]
73pub struct FunctionLoc { 75pub 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)]
81pub struct FunctionId(salsa::InternId);
82impl_intern_key!(FunctionId);
83type FunctionLoc = AssocItemLoc<ast::FnDef>;
84
78impl Intern for FunctionLoc { 85impl 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)]
93pub struct StructId(salsa::InternId); 100pub struct StructId(salsa::InternId);
94impl_intern_key!(StructId); 101impl_intern_key!(StructId);
95 102pub type StructLoc = ItemLoc<ast::StructDef>;
96#[derive(Debug, Clone, PartialEq, Eq, Hash)]
97pub struct StructLoc {
98 pub container: ContainerId,
99 pub ast_id: AstId<ast::StructDef>,
100}
101 103
102impl Intern for StructLoc { 104impl 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)]
117pub struct UnionId(salsa::InternId); 119pub struct UnionId(salsa::InternId);
118impl_intern_key!(UnionId); 120impl_intern_key!(UnionId);
119 121pub type UnionLoc = ItemLoc<ast::UnionDef>;
120#[derive(Debug, Clone, PartialEq, Eq, Hash)]
121pub struct UnionLoc {
122 pub container: ContainerId,
123 pub ast_id: AstId<ast::UnionDef>,
124}
125 122
126impl Intern for UnionLoc { 123impl 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)]
141pub struct EnumId(salsa::InternId); 138pub struct EnumId(salsa::InternId);
142impl_intern_key!(EnumId); 139impl_intern_key!(EnumId);
143 140pub type EnumLoc = ItemLoc<ast::EnumDef>;
144#[derive(Debug, Clone, PartialEq, Eq, Hash)]
145pub struct EnumLoc {
146 pub container: ContainerId,
147 pub ast_id: AstId<ast::EnumDef>,
148}
149 141
150impl Intern for EnumLoc { 142impl 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)]
186pub struct ConstId(salsa::InternId); 178pub struct ConstId(salsa::InternId);
187impl_intern_key!(ConstId); 179impl_intern_key!(ConstId);
188#[derive(Debug, Clone, PartialEq, Eq, Hash)] 180type ConstLoc = AssocItemLoc<ast::ConstDef>;
189pub struct ConstLoc {
190 pub container: AssocContainerId,
191 pub ast_id: AstId<ast::ConstDef>,
192}
193 181
194impl Intern for ConstLoc { 182impl 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)]
209pub struct StaticId(salsa::InternId); 197pub struct StaticId(salsa::InternId);
210impl_intern_key!(StaticId); 198impl_intern_key!(StaticId);
211 199pub type StaticLoc = ItemLoc<ast::StaticDef>;
212#[derive(Debug, Clone, PartialEq, Eq, Hash)]
213pub struct StaticLoc {
214 pub container: ContainerId,
215 pub ast_id: AstId<ast::StaticDef>,
216}
217 200
218impl Intern for StaticLoc { 201impl 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)]
233pub struct TraitId(salsa::InternId); 216pub struct TraitId(salsa::InternId);
234impl_intern_key!(TraitId); 217impl_intern_key!(TraitId);
235 218pub type TraitLoc = ItemLoc<ast::TraitDef>;
236#[derive(Debug, Clone, PartialEq, Eq, Hash)]
237pub struct TraitLoc {
238 pub container: ContainerId,
239 pub ast_id: AstId<ast::TraitDef>,
240}
241 219
242impl Intern for TraitLoc { 220impl 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)]
257pub struct TypeAliasId(salsa::InternId); 235pub struct TypeAliasId(salsa::InternId);
258impl_intern_key!(TypeAliasId); 236impl_intern_key!(TypeAliasId);
259 237type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>;
260#[derive(Debug, Clone, PartialEq, Eq, Hash)]
261pub struct TypeAliasLoc {
262 pub container: AssocContainerId,
263 pub ast_id: AstId<ast::TypeAliasDef>,
264}
265 238
266impl Intern for TypeAliasLoc { 239impl 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)]
278pub struct TypeParamId {
279 pub parent: GenericDefId,
280 pub local_id: LocalTypeParamId,
281}
282
283#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
284pub struct LocalTypeParamId(RawId);
285impl_arena_id!(LocalTypeParamId);
286
304macro_rules! impl_froms { 287macro_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)]
324pub struct TypeParamId {
325 pub parent: GenericDefId,
326 pub local_id: LocalTypeParamId,
327}
328
329#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
330pub struct LocalTypeParamId(RawId);
331impl_arena_id!(LocalTypeParamId);
332
333#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
334pub enum ContainerId { 307pub enum ContainerId {
335 ModuleId(ModuleId), 308 ModuleId(ModuleId),
336 DefWithBodyId(DefWithBodyId), 309 DefWithBodyId(DefWithBodyId),