aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs150
1 files changed, 29 insertions, 121 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 042fd3f8b..faeb2fc8a 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -77,81 +77,45 @@ pub struct AssocItemLoc<N: AstNode> {
77 pub ast_id: AstId<N>, 77 pub ast_id: AstId<N>,
78} 78}
79 79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 80macro_rules! impl_intern {
81pub struct FunctionId(salsa::InternId); 81 ($id:ident, $loc:ident, $intern:ident, $lookup:ident) => {
82impl_intern_key!(FunctionId); 82 impl_intern_key!($id);
83type FunctionLoc = AssocItemLoc<ast::FnDef>; 83
84 impl Intern for $loc {
85 type ID = $id;
86 fn intern(self, db: &impl db::DefDatabase) -> $id {
87 db.$intern(self)
88 }
89 }
84 90
85impl Intern for FunctionLoc { 91 impl Lookup for $id {
86 type ID = FunctionId; 92 type Data = $loc;
87 fn intern(self, db: &impl db::DefDatabase) -> FunctionId { 93 fn lookup(&self, db: &impl db::DefDatabase) -> $loc {
88 db.intern_function(self) 94 db.$lookup(*self)
89 } 95 }
96 }
97 };
90} 98}
91 99
92impl Lookup for FunctionId { 100#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
93 type Data = FunctionLoc; 101pub struct FunctionId(salsa::InternId);
94 fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc { 102type FunctionLoc = AssocItemLoc<ast::FnDef>;
95 db.lookup_intern_function(*self) 103impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function);
96 }
97}
98 104
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 105#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
100pub struct StructId(salsa::InternId); 106pub struct StructId(salsa::InternId);
101impl_intern_key!(StructId); 107type StructLoc = ItemLoc<ast::StructDef>;
102pub type StructLoc = ItemLoc<ast::StructDef>; 108impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct);
103
104impl Intern for StructLoc {
105 type ID = StructId;
106 fn intern(self, db: &impl db::DefDatabase) -> StructId {
107 db.intern_struct(self)
108 }
109}
110
111impl Lookup for StructId {
112 type Data = StructLoc;
113 fn lookup(&self, db: &impl db::DefDatabase) -> StructLoc {
114 db.lookup_intern_struct(*self)
115 }
116}
117 109
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
119pub struct UnionId(salsa::InternId); 111pub struct UnionId(salsa::InternId);
120impl_intern_key!(UnionId);
121pub type UnionLoc = ItemLoc<ast::UnionDef>; 112pub type UnionLoc = ItemLoc<ast::UnionDef>;
122 113impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union);
123impl Intern for UnionLoc {
124 type ID = UnionId;
125 fn intern(self, db: &impl db::DefDatabase) -> UnionId {
126 db.intern_union(self)
127 }
128}
129
130impl Lookup for UnionId {
131 type Data = UnionLoc;
132 fn lookup(&self, db: &impl db::DefDatabase) -> UnionLoc {
133 db.lookup_intern_union(*self)
134 }
135}
136 114
137#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 115#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
138pub struct EnumId(salsa::InternId); 116pub struct EnumId(salsa::InternId);
139impl_intern_key!(EnumId);
140pub type EnumLoc = ItemLoc<ast::EnumDef>; 117pub type EnumLoc = ItemLoc<ast::EnumDef>;
141 118impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum);
142impl Intern for EnumLoc {
143 type ID = EnumId;
144 fn intern(self, db: &impl db::DefDatabase) -> EnumId {
145 db.intern_enum(self)
146 }
147}
148
149impl Lookup for EnumId {
150 type Data = EnumLoc;
151 fn lookup(&self, db: &impl db::DefDatabase) -> EnumLoc {
152 db.lookup_intern_enum(*self)
153 }
154}
155 119
156// FIXME: rename to `VariantId`, only enums can ave variants 120// FIXME: rename to `VariantId`, only enums can ave variants
157#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -176,79 +140,23 @@ impl_arena_id!(LocalStructFieldId);
176 140
177#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 141#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
178pub struct ConstId(salsa::InternId); 142pub struct ConstId(salsa::InternId);
179impl_intern_key!(ConstId);
180type ConstLoc = AssocItemLoc<ast::ConstDef>; 143type ConstLoc = AssocItemLoc<ast::ConstDef>;
181 144impl_intern!(ConstId, ConstLoc, intern_const, lookup_intern_const);
182impl Intern for ConstLoc {
183 type ID = ConstId;
184 fn intern(self, db: &impl db::DefDatabase) -> ConstId {
185 db.intern_const(self)
186 }
187}
188
189impl Lookup for ConstId {
190 type Data = ConstLoc;
191 fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc {
192 db.lookup_intern_const(*self)
193 }
194}
195 145
196#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 146#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
197pub struct StaticId(salsa::InternId); 147pub struct StaticId(salsa::InternId);
198impl_intern_key!(StaticId);
199pub type StaticLoc = ItemLoc<ast::StaticDef>; 148pub type StaticLoc = ItemLoc<ast::StaticDef>;
200 149impl_intern!(StaticId, StaticLoc, intern_static, lookup_intern_static);
201impl Intern for StaticLoc {
202 type ID = StaticId;
203 fn intern(self, db: &impl db::DefDatabase) -> StaticId {
204 db.intern_static(self)
205 }
206}
207
208impl Lookup for StaticId {
209 type Data = StaticLoc;
210 fn lookup(&self, db: &impl db::DefDatabase) -> StaticLoc {
211 db.lookup_intern_static(*self)
212 }
213}
214 150
215#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
216pub struct TraitId(salsa::InternId); 152pub struct TraitId(salsa::InternId);
217impl_intern_key!(TraitId);
218pub type TraitLoc = ItemLoc<ast::TraitDef>; 153pub type TraitLoc = ItemLoc<ast::TraitDef>;
219 154impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait);
220impl Intern for TraitLoc {
221 type ID = TraitId;
222 fn intern(self, db: &impl db::DefDatabase) -> TraitId {
223 db.intern_trait(self)
224 }
225}
226
227impl Lookup for TraitId {
228 type Data = TraitLoc;
229 fn lookup(&self, db: &impl db::DefDatabase) -> TraitLoc {
230 db.lookup_intern_trait(*self)
231 }
232}
233 155
234#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 156#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
235pub struct TypeAliasId(salsa::InternId); 157pub struct TypeAliasId(salsa::InternId);
236impl_intern_key!(TypeAliasId);
237type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>; 158type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>;
238 159impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_alias);
239impl Intern for TypeAliasLoc {
240 type ID = TypeAliasId;
241 fn intern(self, db: &impl db::DefDatabase) -> TypeAliasId {
242 db.intern_type_alias(self)
243 }
244}
245
246impl Lookup for TypeAliasId {
247 type Data = TypeAliasLoc;
248 fn lookup(&self, db: &impl db::DefDatabase) -> TypeAliasLoc {
249 db.lookup_intern_type_alias(*self)
250 }
251}
252 160
253#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 161#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
254pub struct ImplId(salsa::InternId); 162pub struct ImplId(salsa::InternId);