diff options
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 1a599706a..c9e4e6a0f 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -173,24 +173,48 @@ impl Lookup for StructId { | |||
173 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 173 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
174 | pub struct UnionId(salsa::InternId); | 174 | pub struct UnionId(salsa::InternId); |
175 | impl_intern_key!(UnionId); | 175 | impl_intern_key!(UnionId); |
176 | impl AstItemDef<ast::UnionDef> for UnionId { | 176 | |
177 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::UnionDef>) -> Self { | 177 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
178 | db.intern_union(loc) | 178 | pub struct UnionLoc { |
179 | pub container: ModuleId, | ||
180 | pub ast_id: AstId<ast::UnionDef>, | ||
181 | } | ||
182 | |||
183 | impl Intern for UnionLoc { | ||
184 | type ID = UnionId; | ||
185 | fn intern(self, db: &impl db::DefDatabase) -> UnionId { | ||
186 | db.intern_union(self) | ||
179 | } | 187 | } |
180 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::UnionDef> { | 188 | } |
181 | db.lookup_intern_union(self) | 189 | |
190 | impl Lookup for UnionId { | ||
191 | type Data = UnionLoc; | ||
192 | fn lookup(&self, db: &impl db::DefDatabase) -> UnionLoc { | ||
193 | db.lookup_intern_union(*self) | ||
182 | } | 194 | } |
183 | } | 195 | } |
184 | 196 | ||
185 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 197 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
186 | pub struct EnumId(salsa::InternId); | 198 | pub struct EnumId(salsa::InternId); |
187 | impl_intern_key!(EnumId); | 199 | impl_intern_key!(EnumId); |
188 | impl AstItemDef<ast::EnumDef> for EnumId { | 200 | |
189 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::EnumDef>) -> Self { | 201 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
190 | db.intern_enum(loc) | 202 | pub struct EnumLoc { |
203 | pub container: ModuleId, | ||
204 | pub ast_id: AstId<ast::EnumDef>, | ||
205 | } | ||
206 | |||
207 | impl Intern for EnumLoc { | ||
208 | type ID = EnumId; | ||
209 | fn intern(self, db: &impl db::DefDatabase) -> EnumId { | ||
210 | db.intern_enum(self) | ||
191 | } | 211 | } |
192 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::EnumDef> { | 212 | } |
193 | db.lookup_intern_enum(self) | 213 | |
214 | impl Lookup for EnumId { | ||
215 | type Data = EnumLoc; | ||
216 | fn lookup(&self, db: &impl db::DefDatabase) -> EnumLoc { | ||
217 | db.lookup_intern_enum(*self) | ||
194 | } | 218 | } |
195 | } | 219 | } |
196 | 220 | ||
@@ -545,8 +569,8 @@ impl HasModule for AdtId { | |||
545 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 569 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
546 | match self { | 570 | match self { |
547 | AdtId::StructId(it) => it.lookup(db).container, | 571 | AdtId::StructId(it) => it.lookup(db).container, |
548 | AdtId::UnionId(it) => it.module(db), | 572 | AdtId::UnionId(it) => it.lookup(db).container, |
549 | AdtId::EnumId(it) => it.module(db), | 573 | AdtId::EnumId(it) => it.lookup(db).container, |
550 | } | 574 | } |
551 | } | 575 | } |
552 | } | 576 | } |
@@ -569,7 +593,7 @@ impl HasModule for GenericDefId { | |||
569 | GenericDefId::TraitId(it) => it.lookup(db).container, | 593 | GenericDefId::TraitId(it) => it.lookup(db).container, |
570 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), | 594 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), |
571 | GenericDefId::ImplId(it) => it.lookup(db).container, | 595 | GenericDefId::ImplId(it) => it.lookup(db).container, |
572 | GenericDefId::EnumVariantId(it) => it.parent.module(db), | 596 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, |
573 | GenericDefId::ConstId(it) => it.lookup(db).module(db), | 597 | GenericDefId::ConstId(it) => it.lookup(db).module(db), |
574 | } | 598 | } |
575 | } | 599 | } |