From dd5c2dc5bf9e9dee863bd79105b1782b654221f7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 16:49:05 +0300 Subject: Move ImportId --- crates/ra_hir/src/code_model.rs | 8 ++++---- crates/ra_hir_def/src/lib.rs | 4 ++++ crates/ra_hir_def/src/nameres.rs | 8 +++----- crates/ra_hir_def/src/nameres/collector.rs | 14 +++++++------- crates/ra_hir_def/src/nameres/raw.rs | 20 ++++++++------------ 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 50c9a79fc..07c56843a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -9,11 +9,11 @@ use hir_def::{ body::scope::ExprScopes, builtin_type::BuiltinType, docs::Documentation, - nameres::{per_ns::PerNs, raw::ImportId}, + nameres::per_ns::PerNs, resolver::{HasResolver, TypeNs}, type_ref::TypeRef, - ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, - ModuleId, UnionId, + ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalImportId, + LocalStructFieldId, Lookup, ModuleId, UnionId, }; use hir_expand::{ diagnostics::DiagnosticSink, @@ -229,7 +229,7 @@ impl Module { pub struct Import { pub(crate) parent: Module, - pub(crate) id: ImportId, + pub(crate) id: LocalImportId, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 1b2bc6f45..b74038b50 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -99,6 +99,10 @@ impl ModuleSource { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct LocalImportId(RawId); +impl_arena_id!(LocalImportId); + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ModuleId { pub krate: CrateId, diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 101203b7b..0b3b60a37 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -72,11 +72,9 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ builtin_type::BuiltinType, db::DefDatabase, - nameres::{ - diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, - }, + nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs}, path::Path, - AstId, CrateModuleId, FunctionId, ImplId, ModuleDefId, ModuleId, TraitId, + AstId, CrateModuleId, FunctionId, ImplId, LocalImportId, ModuleDefId, ModuleId, TraitId, }; /// Contains all top-level defs from a macro-expanded crate @@ -213,7 +211,7 @@ pub struct Resolution { /// None for unresolved pub def: PerNs, /// ident by which this is imported into local scope. - pub import: Option, + pub import: Option, } impl CrateDefMap { diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 1894b072a..4a671b8f3 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -20,8 +20,8 @@ use crate::{ }, path::{Path, PathKind}, AdtId, AstId, AstItemDef, ConstLoc, ContainerId, CrateModuleId, EnumId, EnumVariantId, - FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, - StructOrUnionId, TraitId, TypeAliasLoc, UnionId, + FunctionLoc, ImplId, Intern, LocalImportId, LocationCtx, ModuleDefId, ModuleId, StaticId, + StructId, StructOrUnionId, TraitId, TypeAliasLoc, UnionId, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -94,8 +94,8 @@ impl MacroStackMonitor { struct DefCollector<'a, DB> { db: &'a DB, def_map: CrateDefMap, - glob_imports: FxHashMap>, - unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>, + glob_imports: FxHashMap>, + unresolved_imports: Vec<(CrateModuleId, LocalImportId, raw::ImportData)>, unexpanded_macros: Vec<(CrateModuleId, AstId, Path)>, mod_dirs: FxHashMap, @@ -293,7 +293,7 @@ where &mut self, module_id: CrateModuleId, def: PerNs, - import_id: raw::ImportId, + import_id: LocalImportId, import: &raw::ImportData, ) { if import.is_glob { @@ -388,7 +388,7 @@ where fn update( &mut self, module_id: CrateModuleId, - import: Option, + import: Option, resolutions: &[(Name, Resolution)], ) { self.update_recursive(module_id, import, resolutions, 0) @@ -397,7 +397,7 @@ where fn update_recursive( &mut self, module_id: CrateModuleId, - import: Option, + import: Option, resolutions: &[(Name, Resolution)], depth: usize, ) { diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 7618cb059..8ee6f54cd 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -20,7 +20,7 @@ use crate::{ attr::{Attr, Attrs}, db::DefDatabase, path::Path, - FileAstId, HirFileId, ModuleSource, Source, + FileAstId, HirFileId, LocalImportId, ModuleSource, Source, }; /// `RawItems` is a set of top-level items in a file (except for impls). @@ -30,7 +30,7 @@ use crate::{ #[derive(Debug, Default, PartialEq, Eq)] pub struct RawItems { modules: Arena, - imports: Arena, + imports: Arena, defs: Arena, macros: Arena, impls: Arena, @@ -40,7 +40,7 @@ pub struct RawItems { #[derive(Debug, Default, PartialEq, Eq)] pub struct ImportSourceMap { - map: ArenaMap, + map: ArenaMap, } type ImportSourcePtr = Either, AstPtr>; @@ -51,11 +51,11 @@ fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { } impl ImportSourceMap { - fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) { + fn insert(&mut self, import: LocalImportId, ptr: ImportSourcePtr) { self.map.insert(import, ptr) } - pub fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { + pub fn get(&self, source: &ModuleSource, import: LocalImportId) -> ImportSource { let file = match source { ModuleSource::SourceFile(file) => file.clone(), ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), @@ -106,9 +106,9 @@ impl Index for RawItems { } } -impl Index for RawItems { +impl Index for RawItems { type Output = ImportData; - fn index(&self, idx: ImportId) -> &ImportData { + fn index(&self, idx: LocalImportId) -> &ImportData { &self.imports[idx] } } @@ -143,7 +143,7 @@ pub(super) struct RawItem { #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(super) enum RawItemKind { Module(Module), - Import(ImportId), + Import(LocalImportId), Def(Def), Macro(Macro), Impl(Impl), @@ -159,10 +159,6 @@ pub(super) enum ModuleData { Definition { name: Name, ast_id: FileAstId, items: Vec }, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct ImportId(RawId); -impl_arena_id!(ImportId); - #[derive(Debug, Clone, PartialEq, Eq)] pub struct ImportData { pub(super) path: Path, -- cgit v1.2.3