diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 2cc175bda..311c0b98a 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -9,7 +9,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | HirDatabase, Def, | 11 | HirDatabase, Def, |
12 | Module, Trait, Type, | 12 | Module, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | #[derive(Debug, Default)] | 15 | #[derive(Debug, Default)] |
@@ -22,6 +22,8 @@ pub struct HirInterner { | |||
22 | enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>, | 22 | enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>, |
23 | consts: LocationIntener<ItemLoc<ast::ConstDef>, ConstId>, | 23 | consts: LocationIntener<ItemLoc<ast::ConstDef>, ConstId>, |
24 | statics: LocationIntener<ItemLoc<ast::StaticDef>, StaticId>, | 24 | statics: LocationIntener<ItemLoc<ast::StaticDef>, StaticId>, |
25 | traits: LocationIntener<ItemLoc<ast::TraitDef>, TraitId>, | ||
26 | types: LocationIntener<ItemLoc<ast::TypeDef>, TypeId>, | ||
25 | } | 27 | } |
26 | 28 | ||
27 | impl HirInterner { | 29 | impl HirInterner { |
@@ -279,6 +281,24 @@ impl AstItemDef<ast::StaticDef> for StaticId { | |||
279 | } | 281 | } |
280 | } | 282 | } |
281 | 283 | ||
284 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
285 | pub struct TraitId(RawId); | ||
286 | impl_arena_id!(TraitId); | ||
287 | impl AstItemDef<ast::TraitDef> for TraitId { | ||
288 | fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::TraitDef>, Self> { | ||
289 | &interner.traits | ||
290 | } | ||
291 | } | ||
292 | |||
293 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
294 | pub struct TypeId(RawId); | ||
295 | impl_arena_id!(TypeId); | ||
296 | impl AstItemDef<ast::TypeDef> for TypeId { | ||
297 | fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::TypeDef>, Self> { | ||
298 | &interner.types | ||
299 | } | ||
300 | } | ||
301 | |||
282 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) | 302 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) |
283 | /// in a specific module. | 303 | /// in a specific module. |
284 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 304 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -294,8 +314,6 @@ pub struct DefLoc { | |||
294 | 314 | ||
295 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 315 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
296 | pub(crate) enum DefKind { | 316 | pub(crate) enum DefKind { |
297 | Trait, | ||
298 | Type, | ||
299 | Item, | 317 | Item, |
300 | // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the | 318 | // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the |
301 | // /// name `Foo` needs to resolve to different types depending on whether we | 319 | // /// name `Foo` needs to resolve to different types depending on whether we |
@@ -317,23 +335,9 @@ impl DefId { | |||
317 | pub fn resolve(self, db: &impl HirDatabase) -> Def { | 335 | pub fn resolve(self, db: &impl HirDatabase) -> Def { |
318 | let loc = self.loc(db); | 336 | let loc = self.loc(db); |
319 | match loc.kind { | 337 | match loc.kind { |
320 | DefKind::Trait => { | ||
321 | let def = Trait::new(self); | ||
322 | Def::Trait(def) | ||
323 | } | ||
324 | DefKind::Type => { | ||
325 | let def = Type::new(self); | ||
326 | Def::Type(def) | ||
327 | } | ||
328 | DefKind::Item => Def::Item, | 338 | DefKind::Item => Def::Item, |
329 | } | 339 | } |
330 | } | 340 | } |
331 | |||
332 | pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) { | ||
333 | let loc = self.loc(db); | ||
334 | let syntax = db.file_item(loc.source_item_id); | ||
335 | (loc.source_item_id.file_id, syntax) | ||
336 | } | ||
337 | } | 341 | } |
338 | 342 | ||
339 | impl DefLoc { | 343 | impl DefLoc { |