From 1ccf73c836d8a70d6f04b621bd6461f133669131 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 01:38:21 +0300 Subject: kill DefKindc --- crates/ra_hir/src/ids.rs | 24 ++-------------------- crates/ra_hir/src/impl_block.rs | 44 +++++++++++------------------------------ crates/ra_hir/src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 55 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 311c0b98a..cbe31f830 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -313,19 +313,7 @@ pub struct DefLoc { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub(crate) enum DefKind { - 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 - // /// are in the types or values namespace: As a type, `Foo` of course refers - // /// to the struct `Foo`; as a value, `Foo` is a callable type with signature - // /// `(usize) -> Foo`. The cleanest approach to handle this seems to be to - // /// have different defs in the two namespaces. - // /// - // /// rustc does the same; note that it even creates a struct constructor if - // /// the struct isn't a tuple struct (see `CtorKind::Fictive` in rustc). - // StructCtor, -} +pub(crate) enum DefKind {} impl DefId { pub(crate) fn loc(self, db: &impl AsRef) -> DefLoc { @@ -334,15 +322,7 @@ impl DefId { pub fn resolve(self, db: &impl HirDatabase) -> Def { let loc = self.loc(db); - match loc.kind { - DefKind::Item => Def::Item, - } - } -} - -impl DefLoc { - pub(crate) fn id(&self, db: &impl AsRef) -> DefId { - db.as_ref().defs.loc2id(&self) + match loc.kind {} } } diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 3df0d3a3b..222e47349 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -5,7 +5,7 @@ use ra_arena::{Arena, RawId, impl_arena_id}; use ra_syntax::ast::{self, AstNode}; use crate::{ - DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, + Const, Type, Function, HirFileId, db::HirDatabase, type_ref::TypeRef, @@ -67,7 +67,6 @@ impl ImplData { pub(crate) fn from_ast( db: &impl HirDatabase, file_id: HirFileId, - file_items: &SourceFileItems, module: Module, node: &ast::ImplBlock, ) -> Self { @@ -77,30 +76,14 @@ impl ImplData { let items = if let Some(item_list) = node.item_list() { item_list .impl_items() - .map(|item_node| { - let kind = match item_node.kind() { - ast::ImplItemKind::FnDef(it) => { - return ImplItem::Method(Function { id: ctx.to_def(it) }); - } - ast::ImplItemKind::ConstDef(..) => DefKind::Item, - ast::ImplItemKind::TypeDef(..) => DefKind::Item, - }; - let item_id = file_items.id_of_unchecked(item_node.syntax()); - let source_item_id = SourceItemId { - file_id, - item_id: Some(item_id), - }; - let def_loc = DefLoc { - module, - kind, - source_item_id, - }; - let def_id = def_loc.id(db); - match item_node.kind() { - ast::ImplItemKind::FnDef(_) => unreachable!(), - ast::ImplItemKind::ConstDef(..) => ImplItem::Const(def_id), - ast::ImplItemKind::TypeDef(..) => ImplItem::Type(def_id), + .map(|item_node| match item_node.kind() { + ast::ImplItemKind::FnDef(it) => { + ImplItem::Method(Function { id: ctx.to_def(it) }) } + ast::ImplItemKind::ConstDef(it) => { + ImplItem::Const(Const { id: ctx.to_def(it) }) + } + ast::ImplItemKind::TypeDef(it) => ImplItem::Type(Type { id: ctx.to_def(it) }), }) .collect() } else { @@ -130,11 +113,11 @@ impl ImplData { //TODO: rename to ImplDef? pub enum ImplItem { Method(Function), - // these don't have their own types yet - Const(DefId), - Type(DefId), + Const(Const), + Type(Type), // Existential } +impl_froms!(ImplItem: Const, Type); impl From for ImplItem { fn from(func: Function) -> ImplItem { @@ -176,11 +159,8 @@ impl ModuleImplBlocks { .syntax(), }; - let source_file_items = db.file_items(file_id); - for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { - let impl_block = - ImplData::from_ast(db, file_id, &source_file_items, module, impl_block_ast); + let impl_block = ImplData::from_ast(db, file_id, module, impl_block_ast); let id = self.impls.alloc(impl_block); for &impl_item in &self.impls[id].items { self.impls_by_def.insert(impl_item, id); diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 33438509c..6cbece95e 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -46,7 +46,7 @@ mod marks; use crate::{ db::HirDatabase, name::{AsName, KnownName}, - ids::{DefKind, SourceItemId, SourceFileItems}, + ids::{SourceItemId, SourceFileItems}, }; pub use self::{ -- cgit v1.2.3