kill DefKindc

This commit is contained in:
Aleksey Kladov 2019-01-25 01:38:21 +03:00
parent ff9c5bef7b
commit 1ccf73c836
3 changed files with 15 additions and 55 deletions

View File

@ -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<HirInterner>) -> 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<HirInterner>) -> DefId {
db.as_ref().defs.loc2id(&self)
match loc.kind {}
}
}

View File

@ -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<Function> 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);

View File

@ -46,7 +46,7 @@ mod marks;
use crate::{
db::HirDatabase,
name::{AsName, KnownName},
ids::{DefKind, SourceItemId, SourceFileItems},
ids::{SourceItemId, SourceFileItems},
};
pub use self::{