Move ImportId
This commit is contained in:
parent
338ff052c2
commit
dd5c2dc5bf
@ -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)]
|
||||
|
@ -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,
|
||||
|
@ -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<ImportId>,
|
||||
pub import: Option<LocalImportId>,
|
||||
}
|
||||
|
||||
impl CrateDefMap {
|
||||
|
@ -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<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>,
|
||||
unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>,
|
||||
glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, LocalImportId)>>,
|
||||
unresolved_imports: Vec<(CrateModuleId, LocalImportId, raw::ImportData)>,
|
||||
unexpanded_macros: Vec<(CrateModuleId, AstId<ast::MacroCall>, Path)>,
|
||||
mod_dirs: FxHashMap<CrateModuleId, ModDir>,
|
||||
|
||||
@ -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<raw::ImportId>,
|
||||
import: Option<LocalImportId>,
|
||||
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<raw::ImportId>,
|
||||
import: Option<LocalImportId>,
|
||||
resolutions: &[(Name, Resolution)],
|
||||
depth: usize,
|
||||
) {
|
||||
|
@ -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<Module, ModuleData>,
|
||||
imports: Arena<ImportId, ImportData>,
|
||||
imports: Arena<LocalImportId, ImportData>,
|
||||
defs: Arena<Def, DefData>,
|
||||
macros: Arena<Macro, MacroData>,
|
||||
impls: Arena<Impl, ImplData>,
|
||||
@ -40,7 +40,7 @@ pub struct RawItems {
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct ImportSourceMap {
|
||||
map: ArenaMap<ImportId, ImportSourcePtr>,
|
||||
map: ArenaMap<LocalImportId, ImportSourcePtr>,
|
||||
}
|
||||
|
||||
type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
|
||||
@ -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<Module> for RawItems {
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<ImportId> for RawItems {
|
||||
impl Index<LocalImportId> 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<ast::Module>, items: Vec<RawItem> },
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user