diff options
author | Aleksey Kladov <[email protected]> | 2019-03-26 15:27:22 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-26 15:27:22 +0000 |
commit | 8f324773127c733b12d1c5ee98a3d9c6a5360db0 (patch) | |
tree | 4cc6186b417ae6cff6bec44f17ce53b1af574010 /crates/ra_hir/src/nameres/raw.rs | |
parent | 071a19537d4399fd04d1e9594ab7878502a12d21 (diff) |
more type safety
Diffstat (limited to 'crates/ra_hir/src/nameres/raw.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 684bd1d50..984478adc 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -12,7 +12,7 @@ use ra_syntax::{ | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, | 14 | DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, |
15 | SourceFileItemId, SourceFileItems, FileAstId, | 15 | SourceFileItems, FileAstId, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | /// `RawItems` is a set of top-level items in a file (except for impls). | 18 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -138,20 +138,19 @@ impl_arena_id!(Def); | |||
138 | 138 | ||
139 | #[derive(Debug, PartialEq, Eq)] | 139 | #[derive(Debug, PartialEq, Eq)] |
140 | pub(super) struct DefData { | 140 | pub(super) struct DefData { |
141 | pub(super) source_item_id: SourceFileItemId, | ||
142 | pub(super) name: Name, | 141 | pub(super) name: Name, |
143 | pub(super) kind: DefKind, | 142 | pub(super) kind: DefKind, |
144 | } | 143 | } |
145 | 144 | ||
146 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 145 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
147 | pub(super) enum DefKind { | 146 | pub(super) enum DefKind { |
148 | Function, | 147 | Function(FileAstId<ast::FnDef>), |
149 | Struct, | 148 | Struct(FileAstId<ast::StructDef>), |
150 | Enum, | 149 | Enum(FileAstId<ast::EnumDef>), |
151 | Const, | 150 | Const(FileAstId<ast::ConstDef>), |
152 | Static, | 151 | Static(FileAstId<ast::StaticDef>), |
153 | Trait, | 152 | Trait(FileAstId<ast::TraitDef>), |
154 | TypeAlias, | 153 | TypeAlias(FileAstId<ast::TypeAliasDef>), |
155 | } | 154 | } |
156 | 155 | ||
157 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -200,18 +199,31 @@ impl RawItemsCollector { | |||
200 | // impls don't participate in name resolution | 199 | // impls don't participate in name resolution |
201 | return; | 200 | return; |
202 | } | 201 | } |
203 | ast::ModuleItemKind::StructDef(it) => (DefKind::Struct, it.name()), | 202 | ast::ModuleItemKind::StructDef(it) => { |
204 | ast::ModuleItemKind::EnumDef(it) => (DefKind::Enum, it.name()), | 203 | (DefKind::Struct(self.source_file_items.ast_id(it)), it.name()) |
205 | ast::ModuleItemKind::FnDef(it) => (DefKind::Function, it.name()), | 204 | } |
206 | ast::ModuleItemKind::TraitDef(it) => (DefKind::Trait, it.name()), | 205 | ast::ModuleItemKind::EnumDef(it) => { |
207 | ast::ModuleItemKind::TypeAliasDef(it) => (DefKind::TypeAlias, it.name()), | 206 | (DefKind::Enum(self.source_file_items.ast_id(it)), it.name()) |
208 | ast::ModuleItemKind::ConstDef(it) => (DefKind::Const, it.name()), | 207 | } |
209 | ast::ModuleItemKind::StaticDef(it) => (DefKind::Static, it.name()), | 208 | ast::ModuleItemKind::FnDef(it) => { |
209 | (DefKind::Function(self.source_file_items.ast_id(it)), it.name()) | ||
210 | } | ||
211 | ast::ModuleItemKind::TraitDef(it) => { | ||
212 | (DefKind::Trait(self.source_file_items.ast_id(it)), it.name()) | ||
213 | } | ||
214 | ast::ModuleItemKind::TypeAliasDef(it) => { | ||
215 | (DefKind::TypeAlias(self.source_file_items.ast_id(it)), it.name()) | ||
216 | } | ||
217 | ast::ModuleItemKind::ConstDef(it) => { | ||
218 | (DefKind::Const(self.source_file_items.ast_id(it)), it.name()) | ||
219 | } | ||
220 | ast::ModuleItemKind::StaticDef(it) => { | ||
221 | (DefKind::Static(self.source_file_items.ast_id(it)), it.name()) | ||
222 | } | ||
210 | }; | 223 | }; |
211 | if let Some(name) = name { | 224 | if let Some(name) = name { |
212 | let name = name.as_name(); | 225 | let name = name.as_name(); |
213 | let source_item_id = self.source_file_items.id_of_unchecked(item.syntax()); | 226 | let def = self.raw_items.defs.alloc(DefData { name, kind }); |
214 | let def = self.raw_items.defs.alloc(DefData { name, kind, source_item_id }); | ||
215 | self.push_item(current_module, RawItem::Def(def)) | 227 | self.push_item(current_module, RawItem::Def(def)) |
216 | } | 228 | } |
217 | } | 229 | } |