From 8f324773127c733b12d1c5ee98a3d9c6a5360db0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Mar 2019 18:27:22 +0300 Subject: more type safety --- crates/ra_hir/src/nameres/raw.rs | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'crates/ra_hir/src/nameres/raw.rs') 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::{ use crate::{ DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, - SourceFileItemId, SourceFileItems, FileAstId, + SourceFileItems, FileAstId, }; /// `RawItems` is a set of top-level items in a file (except for impls). @@ -138,20 +138,19 @@ impl_arena_id!(Def); #[derive(Debug, PartialEq, Eq)] pub(super) struct DefData { - pub(super) source_item_id: SourceFileItemId, pub(super) name: Name, pub(super) kind: DefKind, } #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(super) enum DefKind { - Function, - Struct, - Enum, - Const, - Static, - Trait, - TypeAlias, + Function(FileAstId), + Struct(FileAstId), + Enum(FileAstId), + Const(FileAstId), + Static(FileAstId), + Trait(FileAstId), + TypeAlias(FileAstId), } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -200,18 +199,31 @@ impl RawItemsCollector { // impls don't participate in name resolution return; } - ast::ModuleItemKind::StructDef(it) => (DefKind::Struct, it.name()), - ast::ModuleItemKind::EnumDef(it) => (DefKind::Enum, it.name()), - ast::ModuleItemKind::FnDef(it) => (DefKind::Function, it.name()), - ast::ModuleItemKind::TraitDef(it) => (DefKind::Trait, it.name()), - ast::ModuleItemKind::TypeAliasDef(it) => (DefKind::TypeAlias, it.name()), - ast::ModuleItemKind::ConstDef(it) => (DefKind::Const, it.name()), - ast::ModuleItemKind::StaticDef(it) => (DefKind::Static, it.name()), + ast::ModuleItemKind::StructDef(it) => { + (DefKind::Struct(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::EnumDef(it) => { + (DefKind::Enum(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::FnDef(it) => { + (DefKind::Function(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::TraitDef(it) => { + (DefKind::Trait(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::TypeAliasDef(it) => { + (DefKind::TypeAlias(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::ConstDef(it) => { + (DefKind::Const(self.source_file_items.ast_id(it)), it.name()) + } + ast::ModuleItemKind::StaticDef(it) => { + (DefKind::Static(self.source_file_items.ast_id(it)), it.name()) + } }; if let Some(name) = name { let name = name.as_name(); - let source_item_id = self.source_file_items.id_of_unchecked(item.syntax()); - let def = self.raw_items.defs.alloc(DefData { name, kind, source_item_id }); + let def = self.raw_items.defs.alloc(DefData { name, kind }); self.push_item(current_module, RawItem::Def(def)) } } -- cgit v1.2.3