mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 06:47:34 +00:00
kill DefKindc
This commit is contained in:
parent
ff9c5bef7b
commit
1ccf73c836
@ -313,19 +313,7 @@ pub struct DefLoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum DefKind {
|
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DefId {
|
impl DefId {
|
||||||
pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
|
pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
|
||||||
@ -334,15 +322,7 @@ impl DefId {
|
|||||||
|
|
||||||
pub fn resolve(self, db: &impl HirDatabase) -> Def {
|
pub fn resolve(self, db: &impl HirDatabase) -> Def {
|
||||||
let loc = self.loc(db);
|
let loc = self.loc(db);
|
||||||
match loc.kind {
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
|
|||||||
use ra_syntax::ast::{self, AstNode};
|
use ra_syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DefId, DefLoc, DefKind, SourceItemId, SourceFileItems,
|
Const, Type,
|
||||||
Function, HirFileId,
|
Function, HirFileId,
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
@ -67,7 +67,6 @@ impl ImplData {
|
|||||||
pub(crate) fn from_ast(
|
pub(crate) fn from_ast(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
file_items: &SourceFileItems,
|
|
||||||
module: Module,
|
module: Module,
|
||||||
node: &ast::ImplBlock,
|
node: &ast::ImplBlock,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -77,30 +76,14 @@ impl ImplData {
|
|||||||
let items = if let Some(item_list) = node.item_list() {
|
let items = if let Some(item_list) = node.item_list() {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| {
|
.map(|item_node| match item_node.kind() {
|
||||||
let kind = match item_node.kind() {
|
ast::ImplItemKind::FnDef(it) => {
|
||||||
ast::ImplItemKind::FnDef(it) => {
|
ImplItem::Method(Function { id: ctx.to_def(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),
|
|
||||||
}
|
}
|
||||||
|
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()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
@ -130,11 +113,11 @@ impl ImplData {
|
|||||||
//TODO: rename to ImplDef?
|
//TODO: rename to ImplDef?
|
||||||
pub enum ImplItem {
|
pub enum ImplItem {
|
||||||
Method(Function),
|
Method(Function),
|
||||||
// these don't have their own types yet
|
Const(Const),
|
||||||
Const(DefId),
|
Type(Type),
|
||||||
Type(DefId),
|
|
||||||
// Existential
|
// Existential
|
||||||
}
|
}
|
||||||
|
impl_froms!(ImplItem: Const, Type);
|
||||||
|
|
||||||
impl From<Function> for ImplItem {
|
impl From<Function> for ImplItem {
|
||||||
fn from(func: Function) -> ImplItem {
|
fn from(func: Function) -> ImplItem {
|
||||||
@ -176,11 +159,8 @@ impl ModuleImplBlocks {
|
|||||||
.syntax(),
|
.syntax(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let source_file_items = db.file_items(file_id);
|
|
||||||
|
|
||||||
for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
|
for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
|
||||||
let impl_block =
|
let impl_block = ImplData::from_ast(db, file_id, module, impl_block_ast);
|
||||||
ImplData::from_ast(db, file_id, &source_file_items, module, impl_block_ast);
|
|
||||||
let id = self.impls.alloc(impl_block);
|
let id = self.impls.alloc(impl_block);
|
||||||
for &impl_item in &self.impls[id].items {
|
for &impl_item in &self.impls[id].items {
|
||||||
self.impls_by_def.insert(impl_item, id);
|
self.impls_by_def.insert(impl_item, id);
|
||||||
|
@ -46,7 +46,7 @@ mod marks;
|
|||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
name::{AsName, KnownName},
|
name::{AsName, KnownName},
|
||||||
ids::{DefKind, SourceItemId, SourceFileItems},
|
ids::{SourceItemId, SourceFileItems},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
|
Loading…
Reference in New Issue
Block a user