diff options
author | Aleksey Kladov <[email protected]> | 2019-01-24 22:38:21 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-24 22:38:21 +0000 |
commit | 1ccf73c836d8a70d6f04b621bd6461f133669131 (patch) | |
tree | d3ef92f7da93aa7dde10731139df5b1709335ecb /crates/ra_hir/src/impl_block.rs | |
parent | ff9c5bef7b198cde4358610c565cd0b6dc466de5 (diff) |
kill DefKindc
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 44 |
1 files changed, 12 insertions, 32 deletions
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}; | |||
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast::{self, AstNode}; |
6 | 6 | ||
7 | use crate::{ | 7 | use 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? |
131 | pub enum ImplItem { | 114 | pub 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 | } |
120 | impl_froms!(ImplItem: Const, Type); | ||
138 | 121 | ||
139 | impl From<Function> for ImplItem { | 122 | impl 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); |