aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 22:31:32 +0000
committerAleksey Kladov <[email protected]>2019-01-24 22:31:32 +0000
commit0f2f3a21e7e624f920d182869896347af309e909 (patch)
tree8c16d0a479021c2d558a865df94eb01316a208b2 /crates/ra_hir/src/ids.rs
parent00ba70a0957b8af2813940787238a733298dfa5f (diff)
Migrate trait & type to new ids
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs38
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
10use crate::{ 10use 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
27impl HirInterner { 29impl 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)]
285pub struct TraitId(RawId);
286impl_arena_id!(TraitId);
287impl 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)]
294pub struct TypeId(RawId);
295impl_arena_id!(TypeId);
296impl 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)]
296pub(crate) enum DefKind { 316pub(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
339impl DefLoc { 343impl DefLoc {