diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 150 |
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)] | 80 | macro_rules! impl_intern { |
81 | pub struct FunctionId(salsa::InternId); | 81 | ($id:ident, $loc:ident, $intern:ident, $lookup:ident) => { |
82 | impl_intern_key!(FunctionId); | 82 | impl_intern_key!($id); |
83 | type 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 | ||
85 | impl 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 | ||
92 | impl Lookup for FunctionId { | 100 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
93 | type Data = FunctionLoc; | 101 | pub struct FunctionId(salsa::InternId); |
94 | fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc { | 102 | type FunctionLoc = AssocItemLoc<ast::FnDef>; |
95 | db.lookup_intern_function(*self) | 103 | impl_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)] |
100 | pub struct StructId(salsa::InternId); | 106 | pub struct StructId(salsa::InternId); |
101 | impl_intern_key!(StructId); | 107 | type StructLoc = ItemLoc<ast::StructDef>; |
102 | pub type StructLoc = ItemLoc<ast::StructDef>; | 108 | impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); |
103 | |||
104 | impl Intern for StructLoc { | ||
105 | type ID = StructId; | ||
106 | fn intern(self, db: &impl db::DefDatabase) -> StructId { | ||
107 | db.intern_struct(self) | ||
108 | } | ||
109 | } | ||
110 | |||
111 | impl 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)] |
119 | pub struct UnionId(salsa::InternId); | 111 | pub struct UnionId(salsa::InternId); |
120 | impl_intern_key!(UnionId); | ||
121 | pub type UnionLoc = ItemLoc<ast::UnionDef>; | 112 | pub type UnionLoc = ItemLoc<ast::UnionDef>; |
122 | 113 | impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union); | |
123 | impl Intern for UnionLoc { | ||
124 | type ID = UnionId; | ||
125 | fn intern(self, db: &impl db::DefDatabase) -> UnionId { | ||
126 | db.intern_union(self) | ||
127 | } | ||
128 | } | ||
129 | |||
130 | impl 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)] |
138 | pub struct EnumId(salsa::InternId); | 116 | pub struct EnumId(salsa::InternId); |
139 | impl_intern_key!(EnumId); | ||
140 | pub type EnumLoc = ItemLoc<ast::EnumDef>; | 117 | pub type EnumLoc = ItemLoc<ast::EnumDef>; |
141 | 118 | impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum); | |
142 | impl Intern for EnumLoc { | ||
143 | type ID = EnumId; | ||
144 | fn intern(self, db: &impl db::DefDatabase) -> EnumId { | ||
145 | db.intern_enum(self) | ||
146 | } | ||
147 | } | ||
148 | |||
149 | impl 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)] |
178 | pub struct ConstId(salsa::InternId); | 142 | pub struct ConstId(salsa::InternId); |
179 | impl_intern_key!(ConstId); | ||
180 | type ConstLoc = AssocItemLoc<ast::ConstDef>; | 143 | type ConstLoc = AssocItemLoc<ast::ConstDef>; |
181 | 144 | impl_intern!(ConstId, ConstLoc, intern_const, lookup_intern_const); | |
182 | impl Intern for ConstLoc { | ||
183 | type ID = ConstId; | ||
184 | fn intern(self, db: &impl db::DefDatabase) -> ConstId { | ||
185 | db.intern_const(self) | ||
186 | } | ||
187 | } | ||
188 | |||
189 | impl 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)] |
197 | pub struct StaticId(salsa::InternId); | 147 | pub struct StaticId(salsa::InternId); |
198 | impl_intern_key!(StaticId); | ||
199 | pub type StaticLoc = ItemLoc<ast::StaticDef>; | 148 | pub type StaticLoc = ItemLoc<ast::StaticDef>; |
200 | 149 | impl_intern!(StaticId, StaticLoc, intern_static, lookup_intern_static); | |
201 | impl Intern for StaticLoc { | ||
202 | type ID = StaticId; | ||
203 | fn intern(self, db: &impl db::DefDatabase) -> StaticId { | ||
204 | db.intern_static(self) | ||
205 | } | ||
206 | } | ||
207 | |||
208 | impl 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)] |
216 | pub struct TraitId(salsa::InternId); | 152 | pub struct TraitId(salsa::InternId); |
217 | impl_intern_key!(TraitId); | ||
218 | pub type TraitLoc = ItemLoc<ast::TraitDef>; | 153 | pub type TraitLoc = ItemLoc<ast::TraitDef>; |
219 | 154 | impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait); | |
220 | impl Intern for TraitLoc { | ||
221 | type ID = TraitId; | ||
222 | fn intern(self, db: &impl db::DefDatabase) -> TraitId { | ||
223 | db.intern_trait(self) | ||
224 | } | ||
225 | } | ||
226 | |||
227 | impl 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)] |
235 | pub struct TypeAliasId(salsa::InternId); | 157 | pub struct TypeAliasId(salsa::InternId); |
236 | impl_intern_key!(TypeAliasId); | ||
237 | type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>; | 158 | type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>; |
238 | 159 | impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_alias); | |
239 | impl 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 | |||
246 | impl 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)] |
254 | pub struct ImplId(salsa::InternId); | 162 | pub struct ImplId(salsa::InternId); |