mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 21:23:20 +00:00
Rename CrateModuleId
This commit is contained in:
parent
dd5c2dc5bf
commit
158b1cb524
@ -12,7 +12,7 @@ use hir_def::{
|
|||||||
nameres::per_ns::PerNs,
|
nameres::per_ns::PerNs,
|
||||||
resolver::{HasResolver, TypeNs},
|
resolver::{HasResolver, TypeNs},
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalImportId,
|
ContainerId, HasModule, ImplId, LocalEnumVariantId, LocalImportId, LocalModuleId,
|
||||||
LocalStructFieldId, Lookup, ModuleId, UnionId,
|
LocalStructFieldId, Lookup, ModuleId, UnionId,
|
||||||
};
|
};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
@ -112,7 +112,7 @@ impl_froms!(
|
|||||||
pub use hir_def::{attr::Attrs, ModuleSource};
|
pub use hir_def::{attr::Attrs, ModuleSource};
|
||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module {
|
pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module {
|
||||||
Module { id: ModuleId { krate: krate.crate_id, module_id: crate_module_id } }
|
Module { id: ModuleId { krate: krate.crate_id, module_id: crate_module_id } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ impl Module {
|
|||||||
def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect()
|
def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_module_id(self, module_id: CrateModuleId) -> Module {
|
fn with_module_id(self, module_id: LocalModuleId) -> Module {
|
||||||
Module::new(self.krate(), module_id)
|
Module::new(self.krate(), module_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,14 +106,14 @@ impl_arena_id!(LocalImportId);
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ModuleId {
|
pub struct ModuleId {
|
||||||
pub krate: CrateId,
|
pub krate: CrateId,
|
||||||
pub module_id: CrateModuleId,
|
pub module_id: LocalModuleId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An ID of a module, **local** to a specific crate
|
/// An ID of a module, **local** to a specific crate
|
||||||
// FIXME: rename to `LocalModuleId`.
|
// FIXME: rename to `LocalModuleId`.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct CrateModuleId(RawId);
|
pub struct LocalModuleId(RawId);
|
||||||
impl_arena_id!(CrateModuleId);
|
impl_arena_id!(LocalModuleId);
|
||||||
|
|
||||||
macro_rules! impl_intern_key {
|
macro_rules! impl_intern_key {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
|
@ -74,7 +74,7 @@ use crate::{
|
|||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs},
|
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs},
|
||||||
path::Path,
|
path::Path,
|
||||||
AstId, CrateModuleId, FunctionId, ImplId, LocalImportId, ModuleDefId, ModuleId, TraitId,
|
AstId, FunctionId, ImplId, LocalImportId, LocalModuleId, ModuleDefId, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Contains all top-level defs from a macro-expanded crate
|
/// Contains all top-level defs from a macro-expanded crate
|
||||||
@ -87,8 +87,8 @@ pub struct CrateDefMap {
|
|||||||
/// a dependency (`std` or `core`).
|
/// a dependency (`std` or `core`).
|
||||||
prelude: Option<ModuleId>,
|
prelude: Option<ModuleId>,
|
||||||
extern_prelude: FxHashMap<Name, ModuleDefId>,
|
extern_prelude: FxHashMap<Name, ModuleDefId>,
|
||||||
root: CrateModuleId,
|
root: LocalModuleId,
|
||||||
modules: Arena<CrateModuleId, ModuleData>,
|
modules: Arena<LocalModuleId, ModuleData>,
|
||||||
|
|
||||||
/// Some macros are not well-behavior, which leads to infinite loop
|
/// Some macros are not well-behavior, which leads to infinite loop
|
||||||
/// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } }
|
/// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } }
|
||||||
@ -105,17 +105,17 @@ pub struct CrateDefMap {
|
|||||||
diagnostics: Vec<DefDiagnostic>,
|
diagnostics: Vec<DefDiagnostic>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Index<CrateModuleId> for CrateDefMap {
|
impl std::ops::Index<LocalModuleId> for CrateDefMap {
|
||||||
type Output = ModuleData;
|
type Output = ModuleData;
|
||||||
fn index(&self, id: CrateModuleId) -> &ModuleData {
|
fn index(&self, id: LocalModuleId) -> &ModuleData {
|
||||||
&self.modules[id]
|
&self.modules[id]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
pub struct ModuleData {
|
pub struct ModuleData {
|
||||||
pub parent: Option<CrateModuleId>,
|
pub parent: Option<LocalModuleId>,
|
||||||
pub children: FxHashMap<Name, CrateModuleId>,
|
pub children: FxHashMap<Name, LocalModuleId>,
|
||||||
pub scope: ModuleScope,
|
pub scope: ModuleScope,
|
||||||
|
|
||||||
// FIXME: these can't be both null, we need a three-state enum here.
|
// FIXME: these can't be both null, we need a three-state enum here.
|
||||||
@ -225,7 +225,7 @@ impl CrateDefMap {
|
|||||||
let def_map = {
|
let def_map = {
|
||||||
let crate_graph = db.crate_graph();
|
let crate_graph = db.crate_graph();
|
||||||
let edition = crate_graph.edition(krate);
|
let edition = crate_graph.edition(krate);
|
||||||
let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default();
|
let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
|
||||||
let root = modules.alloc(ModuleData::default());
|
let root = modules.alloc(ModuleData::default());
|
||||||
CrateDefMap {
|
CrateDefMap {
|
||||||
krate,
|
krate,
|
||||||
@ -246,7 +246,7 @@ impl CrateDefMap {
|
|||||||
self.krate
|
self.krate
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root(&self) -> CrateModuleId {
|
pub fn root(&self) -> LocalModuleId {
|
||||||
self.root
|
self.root
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ impl CrateDefMap {
|
|||||||
pub fn add_diagnostics(
|
pub fn add_diagnostics(
|
||||||
&self,
|
&self,
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
module: CrateModuleId,
|
module: LocalModuleId,
|
||||||
sink: &mut DiagnosticSink,
|
sink: &mut DiagnosticSink,
|
||||||
) {
|
) {
|
||||||
self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink))
|
self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink))
|
||||||
@ -270,18 +270,18 @@ impl CrateDefMap {
|
|||||||
pub fn resolve_path(
|
pub fn resolve_path(
|
||||||
&self,
|
&self,
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
original_module: CrateModuleId,
|
original_module: LocalModuleId,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> (PerNs, Option<usize>) {
|
) -> (PerNs, Option<usize>) {
|
||||||
let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
|
let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
|
||||||
(res.resolved_def, res.segment_index)
|
(res.resolved_def, res.segment_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn modules(&self) -> impl Iterator<Item = CrateModuleId> + '_ {
|
pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ {
|
||||||
self.modules.iter().map(|(id, _data)| id)
|
self.modules.iter().map(|(id, _data)| id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = CrateModuleId> + '_ {
|
pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = LocalModuleId> + '_ {
|
||||||
self.modules
|
self.modules
|
||||||
.iter()
|
.iter()
|
||||||
.filter(move |(_id, data)| data.definition == Some(file_id))
|
.filter(move |(_id, data)| data.definition == Some(file_id))
|
||||||
@ -317,12 +317,12 @@ mod diagnostics {
|
|||||||
use ra_db::RelativePathBuf;
|
use ra_db::RelativePathBuf;
|
||||||
use ra_syntax::{ast, AstPtr};
|
use ra_syntax::{ast, AstPtr};
|
||||||
|
|
||||||
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::CrateModuleId, AstId};
|
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub(super) enum DefDiagnostic {
|
pub(super) enum DefDiagnostic {
|
||||||
UnresolvedModule {
|
UnresolvedModule {
|
||||||
module: CrateModuleId,
|
module: LocalModuleId,
|
||||||
declaration: AstId<ast::Module>,
|
declaration: AstId<ast::Module>,
|
||||||
candidate: RelativePathBuf,
|
candidate: RelativePathBuf,
|
||||||
},
|
},
|
||||||
@ -332,7 +332,7 @@ mod diagnostics {
|
|||||||
pub(super) fn add_to(
|
pub(super) fn add_to(
|
||||||
&self,
|
&self,
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
target_module: CrateModuleId,
|
target_module: LocalModuleId,
|
||||||
sink: &mut DiagnosticSink,
|
sink: &mut DiagnosticSink,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
|
@ -19,9 +19,9 @@ use crate::{
|
|||||||
per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode,
|
per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode,
|
||||||
},
|
},
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
AdtId, AstId, AstItemDef, ConstLoc, ContainerId, CrateModuleId, EnumId, EnumVariantId,
|
AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId,
|
||||||
FunctionLoc, ImplId, Intern, LocalImportId, LocationCtx, ModuleDefId, ModuleId, StaticId,
|
Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId,
|
||||||
StructId, StructOrUnionId, TraitId, TypeAliasLoc, UnionId,
|
StructOrUnionId, TraitId, TypeAliasLoc, UnionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||||
@ -94,10 +94,10 @@ impl MacroStackMonitor {
|
|||||||
struct DefCollector<'a, DB> {
|
struct DefCollector<'a, DB> {
|
||||||
db: &'a DB,
|
db: &'a DB,
|
||||||
def_map: CrateDefMap,
|
def_map: CrateDefMap,
|
||||||
glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, LocalImportId)>>,
|
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>,
|
||||||
unresolved_imports: Vec<(CrateModuleId, LocalImportId, raw::ImportData)>,
|
unresolved_imports: Vec<(LocalModuleId, LocalImportId, raw::ImportData)>,
|
||||||
unexpanded_macros: Vec<(CrateModuleId, AstId<ast::MacroCall>, Path)>,
|
unexpanded_macros: Vec<(LocalModuleId, AstId<ast::MacroCall>, Path)>,
|
||||||
mod_dirs: FxHashMap<CrateModuleId, ModDir>,
|
mod_dirs: FxHashMap<LocalModuleId, ModDir>,
|
||||||
|
|
||||||
/// Some macro use `$tt:tt which mean we have to handle the macro perfectly
|
/// Some macro use `$tt:tt which mean we have to handle the macro perfectly
|
||||||
/// To prevent stack overflow, we add a deep counter here for prevent that.
|
/// To prevent stack overflow, we add a deep counter here for prevent that.
|
||||||
@ -173,7 +173,7 @@ where
|
|||||||
/// ```
|
/// ```
|
||||||
fn define_macro(
|
fn define_macro(
|
||||||
&mut self,
|
&mut self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
name: Name,
|
name: Name,
|
||||||
macro_: MacroDefId,
|
macro_: MacroDefId,
|
||||||
export: bool,
|
export: bool,
|
||||||
@ -200,7 +200,7 @@ where
|
|||||||
/// the definition of current module.
|
/// the definition of current module.
|
||||||
/// And also, `macro_use` on a module will import all legacy macros visable inside to
|
/// And also, `macro_use` on a module will import all legacy macros visable inside to
|
||||||
/// current legacy scope, with possible shadowing.
|
/// current legacy scope, with possible shadowing.
|
||||||
fn define_legacy_macro(&mut self, module_id: CrateModuleId, name: Name, macro_: MacroDefId) {
|
fn define_legacy_macro(&mut self, module_id: LocalModuleId, name: Name, macro_: MacroDefId) {
|
||||||
// Always shadowing
|
// Always shadowing
|
||||||
self.def_map.modules[module_id].scope.legacy_macros.insert(name, macro_);
|
self.def_map.modules[module_id].scope.legacy_macros.insert(name, macro_);
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ where
|
|||||||
/// Import macros from `#[macro_use] extern crate`.
|
/// Import macros from `#[macro_use] extern crate`.
|
||||||
fn import_macros_from_extern_crate(
|
fn import_macros_from_extern_crate(
|
||||||
&mut self,
|
&mut self,
|
||||||
current_module_id: CrateModuleId,
|
current_module_id: LocalModuleId,
|
||||||
import: &raw::ImportData,
|
import: &raw::ImportData,
|
||||||
) {
|
) {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
@ -235,7 +235,7 @@ where
|
|||||||
/// Exported macros are just all macros in the root module scope.
|
/// Exported macros are just all macros in the root module scope.
|
||||||
/// Note that it contains not only all `#[macro_export]` macros, but also all aliases
|
/// Note that it contains not only all `#[macro_export]` macros, but also all aliases
|
||||||
/// created by `use` in the root module, ignoring the visibility of `use`.
|
/// created by `use` in the root module, ignoring the visibility of `use`.
|
||||||
fn import_all_macros_exported(&mut self, current_module_id: CrateModuleId, krate: CrateId) {
|
fn import_all_macros_exported(&mut self, current_module_id: LocalModuleId, krate: CrateId) {
|
||||||
let def_map = self.db.crate_def_map(krate);
|
let def_map = self.db.crate_def_map(krate);
|
||||||
for (name, def) in def_map[def_map.root].scope.macros() {
|
for (name, def) in def_map[def_map.root].scope.macros() {
|
||||||
// `macro_use` only bring things into legacy scope.
|
// `macro_use` only bring things into legacy scope.
|
||||||
@ -265,7 +265,7 @@ where
|
|||||||
|
|
||||||
fn resolve_import(
|
fn resolve_import(
|
||||||
&self,
|
&self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
import: &raw::ImportData,
|
import: &raw::ImportData,
|
||||||
) -> (PerNs, ReachedFixedPoint) {
|
) -> (PerNs, ReachedFixedPoint) {
|
||||||
log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition);
|
log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition);
|
||||||
@ -291,7 +291,7 @@ where
|
|||||||
|
|
||||||
fn record_resolved_import(
|
fn record_resolved_import(
|
||||||
&mut self,
|
&mut self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
def: PerNs,
|
def: PerNs,
|
||||||
import_id: LocalImportId,
|
import_id: LocalImportId,
|
||||||
import: &raw::ImportData,
|
import: &raw::ImportData,
|
||||||
@ -387,7 +387,7 @@ where
|
|||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
import: Option<LocalImportId>,
|
import: Option<LocalImportId>,
|
||||||
resolutions: &[(Name, Resolution)],
|
resolutions: &[(Name, Resolution)],
|
||||||
) {
|
) {
|
||||||
@ -396,7 +396,7 @@ where
|
|||||||
|
|
||||||
fn update_recursive(
|
fn update_recursive(
|
||||||
&mut self,
|
&mut self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
import: Option<LocalImportId>,
|
import: Option<LocalImportId>,
|
||||||
resolutions: &[(Name, Resolution)],
|
resolutions: &[(Name, Resolution)],
|
||||||
depth: usize,
|
depth: usize,
|
||||||
@ -484,7 +484,7 @@ where
|
|||||||
|
|
||||||
fn collect_macro_expansion(
|
fn collect_macro_expansion(
|
||||||
&mut self,
|
&mut self,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
macro_call_id: MacroCallId,
|
macro_call_id: MacroCallId,
|
||||||
macro_def_id: MacroDefId,
|
macro_def_id: MacroDefId,
|
||||||
) {
|
) {
|
||||||
@ -522,7 +522,7 @@ where
|
|||||||
/// Walks a single module, populating defs, imports and macros
|
/// Walks a single module, populating defs, imports and macros
|
||||||
struct ModCollector<'a, D> {
|
struct ModCollector<'a, D> {
|
||||||
def_collector: D,
|
def_collector: D,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
raw_items: &'a raw::RawItems,
|
raw_items: &'a raw::RawItems,
|
||||||
mod_dir: ModDir,
|
mod_dir: ModDir,
|
||||||
@ -647,7 +647,7 @@ where
|
|||||||
name: Name,
|
name: Name,
|
||||||
declaration: AstId<ast::Module>,
|
declaration: AstId<ast::Module>,
|
||||||
definition: Option<FileId>,
|
definition: Option<FileId>,
|
||||||
) -> CrateModuleId {
|
) -> LocalModuleId {
|
||||||
let modules = &mut self.def_collector.def_map.modules;
|
let modules = &mut self.def_collector.def_map.modules;
|
||||||
let res = modules.alloc(ModuleData::default());
|
let res = modules.alloc(ModuleData::default());
|
||||||
modules[res].parent = Some(self.module_id);
|
modules[res].parent = Some(self.module_id);
|
||||||
@ -772,7 +772,7 @@ where
|
|||||||
self.def_collector.unexpanded_macros.push((self.module_id, ast_id, path));
|
self.def_collector.unexpanded_macros.push((self.module_id, ast_id, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_all_legacy_macros(&mut self, module_id: CrateModuleId) {
|
fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) {
|
||||||
let macros = self.def_collector.def_map[module_id].scope.legacy_macros.clone();
|
let macros = self.def_collector.def_map[module_id].scope.legacy_macros.clone();
|
||||||
for (name, macro_) in macros {
|
for (name, macro_) in macros {
|
||||||
self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_);
|
self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_);
|
||||||
@ -827,7 +827,7 @@ mod tests {
|
|||||||
|
|
||||||
let def_map = {
|
let def_map = {
|
||||||
let edition = db.crate_graph().edition(krate);
|
let edition = db.crate_graph().edition(krate);
|
||||||
let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default();
|
let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
|
||||||
let root = modules.alloc(ModuleData::default());
|
let root = modules.alloc(ModuleData::default());
|
||||||
CrateDefMap {
|
CrateDefMap {
|
||||||
krate,
|
krate,
|
||||||
|
@ -18,7 +18,7 @@ use crate::{
|
|||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
nameres::{per_ns::PerNs, CrateDefMap},
|
nameres::{per_ns::PerNs, CrateDefMap},
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
AdtId, CrateModuleId, EnumVariantId, ModuleDefId, ModuleId,
|
AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@ -65,7 +65,7 @@ impl CrateDefMap {
|
|||||||
&self,
|
&self,
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
mode: ResolveMode,
|
mode: ResolveMode,
|
||||||
original_module: CrateModuleId,
|
original_module: LocalModuleId,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> ResolvePathResult {
|
) -> ResolvePathResult {
|
||||||
let mut segments = path.segments.iter().enumerate();
|
let mut segments = path.segments.iter().enumerate();
|
||||||
@ -217,7 +217,7 @@ impl CrateDefMap {
|
|||||||
fn resolve_name_in_module(
|
fn resolve_name_in_module(
|
||||||
&self,
|
&self,
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
module: CrateModuleId,
|
module: LocalModuleId,
|
||||||
name: &Name,
|
name: &Name,
|
||||||
) -> PerNs {
|
) -> PerNs {
|
||||||
// Resolve in:
|
// Resolve in:
|
||||||
|
@ -10,7 +10,7 @@ use insta::assert_snapshot;
|
|||||||
use ra_db::{fixture::WithFixture, SourceDatabase};
|
use ra_db::{fixture::WithFixture, SourceDatabase};
|
||||||
use test_utils::covers;
|
use test_utils::covers;
|
||||||
|
|
||||||
use crate::{db::DefDatabase, nameres::*, test_db::TestDB, CrateModuleId};
|
use crate::{db::DefDatabase, nameres::*, test_db::TestDB, LocalModuleId};
|
||||||
|
|
||||||
fn def_map(fixtute: &str) -> String {
|
fn def_map(fixtute: &str) -> String {
|
||||||
let dm = compute_crate_def_map(fixtute);
|
let dm = compute_crate_def_map(fixtute);
|
||||||
@ -28,7 +28,7 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
|
|||||||
go(&mut buf, map, "\ncrate", map.root());
|
go(&mut buf, map, "\ncrate", map.root());
|
||||||
return buf.trim().to_string();
|
return buf.trim().to_string();
|
||||||
|
|
||||||
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) {
|
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
|
||||||
*buf += path;
|
*buf += path;
|
||||||
*buf += "\n";
|
*buf += "\n";
|
||||||
|
|
||||||
|
@ -665,7 +665,7 @@ fn unresolved_module_diagnostics() {
|
|||||||
@r###"
|
@r###"
|
||||||
[
|
[
|
||||||
UnresolvedModule {
|
UnresolvedModule {
|
||||||
module: CrateModuleId(
|
module: LocalModuleId(
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
declaration: AstId {
|
declaration: AstId {
|
||||||
|
@ -16,9 +16,9 @@ use crate::{
|
|||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
nameres::{per_ns::PerNs, CrateDefMap},
|
nameres::{per_ns::PerNs, CrateDefMap},
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
AdtId, AstItemDef, ConstId, ContainerId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId,
|
AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
|
||||||
FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
|
GenericDefId, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId,
|
||||||
TypeAliasId,
|
TraitId, TypeAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
@ -30,7 +30,7 @@ pub struct Resolver {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct ModuleItemMap {
|
pub(crate) struct ModuleItemMap {
|
||||||
crate_def_map: Arc<CrateDefMap>,
|
crate_def_map: Arc<CrateDefMap>,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -330,7 +330,7 @@ impl Resolver {
|
|||||||
traits
|
traits
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> {
|
fn module(&self) -> Option<(&CrateDefMap, LocalModuleId)> {
|
||||||
self.scopes.iter().rev().find_map(|scope| match scope {
|
self.scopes.iter().rev().find_map(|scope| match scope {
|
||||||
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
|
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
|
||||||
|
|
||||||
@ -466,7 +466,7 @@ impl Resolver {
|
|||||||
fn push_module_scope(
|
fn push_module_scope(
|
||||||
self,
|
self,
|
||||||
crate_def_map: Arc<CrateDefMap>,
|
crate_def_map: Arc<CrateDefMap>,
|
||||||
module_id: CrateModuleId,
|
module_id: LocalModuleId,
|
||||||
) -> Resolver {
|
) -> Resolver {
|
||||||
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
|
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user