aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/ids.rs24
-rw-r--r--crates/ra_hir/src/impl_block.rs44
-rw-r--r--crates/ra_hir/src/lib.rs2
3 files changed, 15 insertions, 55 deletions
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 {
313} 313}
314 314
315#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 315#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
316pub(crate) enum DefKind { 316pub(crate) enum DefKind {}
317 Item,
318 // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the
319 // /// name `Foo` needs to resolve to different types depending on whether we
320 // /// are in the types or values namespace: As a type, `Foo` of course refers
321 // /// to the struct `Foo`; as a value, `Foo` is a callable type with signature
322 // /// `(usize) -> Foo`. The cleanest approach to handle this seems to be to
323 // /// have different defs in the two namespaces.
324 // ///
325 // /// rustc does the same; note that it even creates a struct constructor if
326 // /// the struct isn't a tuple struct (see `CtorKind::Fictive` in rustc).
327 // StructCtor,
328}
329 317
330impl DefId { 318impl DefId {
331 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc { 319 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
@@ -334,15 +322,7 @@ impl DefId {
334 322
335 pub fn resolve(self, db: &impl HirDatabase) -> Def { 323 pub fn resolve(self, db: &impl HirDatabase) -> Def {
336 let loc = self.loc(db); 324 let loc = self.loc(db);
337 match loc.kind { 325 match loc.kind {}
338 DefKind::Item => Def::Item,
339 }
340 }
341}
342
343impl DefLoc {
344 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> DefId {
345 db.as_ref().defs.loc2id(&self)
346 } 326 }
347} 327}
348 328
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};
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::ast::{self, AstNode};
6 6
7use crate::{ 7use crate::{
8 DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, 8 Const, Type,
9 Function, HirFileId, 9 Function, HirFileId,
10 db::HirDatabase, 10 db::HirDatabase,
11 type_ref::TypeRef, 11 type_ref::TypeRef,
@@ -67,7 +67,6 @@ impl ImplData {
67 pub(crate) fn from_ast( 67 pub(crate) fn from_ast(
68 db: &impl HirDatabase, 68 db: &impl HirDatabase,
69 file_id: HirFileId, 69 file_id: HirFileId,
70 file_items: &SourceFileItems,
71 module: Module, 70 module: Module,
72 node: &ast::ImplBlock, 71 node: &ast::ImplBlock,
73 ) -> Self { 72 ) -> Self {
@@ -77,30 +76,14 @@ impl ImplData {
77 let items = if let Some(item_list) = node.item_list() { 76 let items = if let Some(item_list) = node.item_list() {
78 item_list 77 item_list
79 .impl_items() 78 .impl_items()
80 .map(|item_node| { 79 .map(|item_node| match item_node.kind() {
81 let kind = match item_node.kind() { 80 ast::ImplItemKind::FnDef(it) => {
82 ast::ImplItemKind::FnDef(it) => { 81 ImplItem::Method(Function { id: ctx.to_def(it) })
83 return ImplItem::Method(Function { id: ctx.to_def(it) });
84 }
85 ast::ImplItemKind::ConstDef(..) => DefKind::Item,
86 ast::ImplItemKind::TypeDef(..) => DefKind::Item,
87 };
88 let item_id = file_items.id_of_unchecked(item_node.syntax());
89 let source_item_id = SourceItemId {
90 file_id,
91 item_id: Some(item_id),
92 };
93 let def_loc = DefLoc {
94 module,
95 kind,
96 source_item_id,
97 };
98 let def_id = def_loc.id(db);
99 match item_node.kind() {
100 ast::ImplItemKind::FnDef(_) => unreachable!(),
101 ast::ImplItemKind::ConstDef(..) => ImplItem::Const(def_id),
102 ast::ImplItemKind::TypeDef(..) => ImplItem::Type(def_id),
103 } 82 }
83 ast::ImplItemKind::ConstDef(it) => {
84 ImplItem::Const(Const { id: ctx.to_def(it) })
85 }
86 ast::ImplItemKind::TypeDef(it) => ImplItem::Type(Type { id: ctx.to_def(it) }),
104 }) 87 })
105 .collect() 88 .collect()
106 } else { 89 } else {
@@ -130,11 +113,11 @@ impl ImplData {
130//TODO: rename to ImplDef? 113//TODO: rename to ImplDef?
131pub enum ImplItem { 114pub enum ImplItem {
132 Method(Function), 115 Method(Function),
133 // these don't have their own types yet 116 Const(Const),
134 Const(DefId), 117 Type(Type),
135 Type(DefId),
136 // Existential 118 // Existential
137} 119}
120impl_froms!(ImplItem: Const, Type);
138 121
139impl From<Function> for ImplItem { 122impl From<Function> for ImplItem {
140 fn from(func: Function) -> ImplItem { 123 fn from(func: Function) -> ImplItem {
@@ -176,11 +159,8 @@ impl ModuleImplBlocks {
176 .syntax(), 159 .syntax(),
177 }; 160 };
178 161
179 let source_file_items = db.file_items(file_id);
180
181 for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { 162 for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
182 let impl_block = 163 let impl_block = ImplData::from_ast(db, file_id, module, impl_block_ast);
183 ImplData::from_ast(db, file_id, &source_file_items, module, impl_block_ast);
184 let id = self.impls.alloc(impl_block); 164 let id = self.impls.alloc(impl_block);
185 for &impl_item in &self.impls[id].items { 165 for &impl_item in &self.impls[id].items {
186 self.impls_by_def.insert(impl_item, id); 166 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;
46use crate::{ 46use crate::{
47 db::HirDatabase, 47 db::HirDatabase,
48 name::{AsName, KnownName}, 48 name::{AsName, KnownName},
49 ids::{DefKind, SourceItemId, SourceFileItems}, 49 ids::{SourceItemId, SourceFileItems},
50}; 50};
51 51
52pub use self::{ 52pub use self::{