From 0f2f3a21e7e624f920d182869896347af309e909 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 01:31:32 +0300 Subject: Migrate trait & type to new ids --- crates/ra_hir/src/ids.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir/src/ids.rs') 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}; use crate::{ HirDatabase, Def, - Module, Trait, Type, + Module, }; #[derive(Debug, Default)] @@ -22,6 +22,8 @@ pub struct HirInterner { enum_variants: LocationIntener, EnumVariantId>, consts: LocationIntener, ConstId>, statics: LocationIntener, StaticId>, + traits: LocationIntener, TraitId>, + types: LocationIntener, TypeId>, } impl HirInterner { @@ -279,6 +281,24 @@ impl AstItemDef for StaticId { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct TraitId(RawId); +impl_arena_id!(TraitId); +impl AstItemDef for TraitId { + fn interner(interner: &HirInterner) -> &LocationIntener, Self> { + &interner.traits + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct TypeId(RawId); +impl_arena_id!(TypeId); +impl AstItemDef for TypeId { + fn interner(interner: &HirInterner) -> &LocationIntener, Self> { + &interner.types + } +} + /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) /// in a specific module. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -294,8 +314,6 @@ pub struct DefLoc { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub(crate) enum DefKind { - Trait, - Type, Item, // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the // /// name `Foo` needs to resolve to different types depending on whether we @@ -317,23 +335,9 @@ impl DefId { pub fn resolve(self, db: &impl HirDatabase) -> Def { let loc = self.loc(db); match loc.kind { - DefKind::Trait => { - let def = Trait::new(self); - Def::Trait(def) - } - DefKind::Type => { - let def = Type::new(self); - Def::Type(def) - } DefKind::Item => Def::Item, } } - - pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { - let loc = self.loc(db); - let syntax = db.file_item(loc.source_item_id); - (loc.source_item_id.file_id, syntax) - } } impl DefLoc { -- cgit v1.2.3