mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Rename module_id -> local_id
This commit is contained in:
parent
47ec2ceb12
commit
d9a36a736b
13 changed files with 47 additions and 47 deletions
|
@ -174,15 +174,15 @@ pub use hir_def::attr::Attrs;
|
|||
|
||||
impl 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, local_id: crate_module_id } }
|
||||
}
|
||||
|
||||
/// Name of this module.
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let parent = def_map[self.id.module_id].parent?;
|
||||
let parent = def_map[self.id.local_id].parent?;
|
||||
def_map[parent].children.iter().find_map(|(name, module_id)| {
|
||||
if *module_id == self.id.module_id {
|
||||
if *module_id == self.id.local_id {
|
||||
Some(name.clone())
|
||||
} else {
|
||||
None
|
||||
|
@ -206,14 +206,14 @@ impl Module {
|
|||
/// Finds a child module with the specified name.
|
||||
pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let child_id = def_map[self.id.module_id].children.get(name)?;
|
||||
let child_id = def_map[self.id.local_id].children.get(name)?;
|
||||
Some(self.with_module_id(*child_id))
|
||||
}
|
||||
|
||||
/// Iterates over all child modules.
|
||||
pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let children = def_map[self.id.module_id]
|
||||
let children = def_map[self.id.local_id]
|
||||
.children
|
||||
.iter()
|
||||
.map(|(_, module_id)| self.with_module_id(*module_id))
|
||||
|
@ -224,7 +224,7 @@ impl Module {
|
|||
/// Finds a parent module.
|
||||
pub fn parent(self, db: &impl DefDatabase) -> Option<Module> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let parent_id = def_map[self.id.module_id].parent?;
|
||||
let parent_id = def_map[self.id.local_id].parent?;
|
||||
Some(self.with_module_id(parent_id))
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ impl Module {
|
|||
|
||||
/// Returns a `ModuleScope`: a set of items, visible in this module.
|
||||
pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> {
|
||||
db.crate_def_map(self.id.krate)[self.id.module_id]
|
||||
db.crate_def_map(self.id.krate)[self.id.local_id]
|
||||
.scope
|
||||
.entries()
|
||||
.map(|(name, res)| {
|
||||
|
@ -250,7 +250,7 @@ impl Module {
|
|||
}
|
||||
|
||||
pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
|
||||
db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.module_id, sink);
|
||||
db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink);
|
||||
for decl in self.declarations(db) {
|
||||
match decl {
|
||||
crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
|
||||
|
@ -275,12 +275,12 @@ impl Module {
|
|||
|
||||
pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect()
|
||||
def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect()
|
||||
}
|
||||
|
||||
pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect()
|
||||
def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect()
|
||||
}
|
||||
|
||||
fn with_module_id(self, module_id: LocalModuleId) -> Module {
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Module {
|
|||
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
|
||||
pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let src = def_map[self.id.module_id].definition_source(db);
|
||||
let src = def_map[self.id.local_id].definition_source(db);
|
||||
src.map(|it| match it {
|
||||
Either::A(it) => ModuleSource::SourceFile(it),
|
||||
Either::B(it) => ModuleSource::Module(it),
|
||||
|
@ -33,7 +33,7 @@ impl Module {
|
|||
/// `None` for the crate root.
|
||||
pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
def_map[self.id.module_id].declaration_source(db)
|
||||
def_map[self.id.local_id].declaration_source(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -262,13 +262,13 @@ impl Module {
|
|||
|
||||
let original_file = src.file_id.original_file(db);
|
||||
|
||||
let (krate, module_id) =
|
||||
let (krate, local_id) =
|
||||
db.relevant_crates(original_file).iter().find_map(|&crate_id| {
|
||||
let crate_def_map = db.crate_def_map(crate_id);
|
||||
let local_module_id = crate_def_map.modules_for_file(original_file).next()?;
|
||||
Some((crate_id, local_module_id))
|
||||
let local_id = crate_def_map.modules_for_file(original_file).next()?;
|
||||
Some((crate_id, local_id))
|
||||
})?;
|
||||
Some(Module { id: ModuleId { krate, module_id } })
|
||||
Some(Module { id: ModuleId { krate, local_id } })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Attrs {
|
|||
match def {
|
||||
AttrDefId::ModuleId(module) => {
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
let src = match def_map[module.module_id].declaration_source(db) {
|
||||
let src = match def_map[module.local_id].declaration_source(db) {
|
||||
Some(it) => it,
|
||||
None => return Attrs::default(),
|
||||
};
|
||||
|
|
|
@ -82,7 +82,7 @@ impl Expander {
|
|||
}
|
||||
|
||||
fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
|
||||
self.crate_def_map.resolve_path(db, self.module.module_id, path).0.take_macros()
|
||||
self.crate_def_map.resolve_path(db, self.module.local_id, path).0.take_macros()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ impl Documentation {
|
|||
match def {
|
||||
AttrDefId::ModuleId(module) => {
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
let src = def_map[module.module_id].declaration_source(db)?;
|
||||
let src = def_map[module.local_id].declaration_source(db)?;
|
||||
docs_from_ast(&src.value)
|
||||
}
|
||||
AttrDefId::StructFieldId(it) => {
|
||||
|
|
|
@ -41,7 +41,7 @@ impl LangItems {
|
|||
crate_def_map
|
||||
.modules
|
||||
.iter()
|
||||
.filter_map(|(module_id, _)| db.module_lang_items(ModuleId { krate, module_id }))
|
||||
.filter_map(|(local_id, _)| db.module_lang_items(ModuleId { krate, local_id }))
|
||||
.for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v))));
|
||||
|
||||
Arc::new(lang_items)
|
||||
|
@ -80,7 +80,7 @@ impl LangItems {
|
|||
fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) {
|
||||
// Look for impl targets
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
let module_data = &def_map[module.module_id];
|
||||
let module_data = &def_map[module.local_id];
|
||||
for &impl_block in module_data.impls.iter() {
|
||||
self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ impl_arena_id!(LocalImportId);
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ModuleId {
|
||||
pub krate: CrateId,
|
||||
pub module_id: LocalModuleId,
|
||||
pub local_id: LocalModuleId,
|
||||
}
|
||||
|
||||
/// An ID of a module, **local** to a specific crate
|
||||
|
|
|
@ -37,7 +37,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
|
|||
log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
|
||||
def_map.extern_prelude.insert(
|
||||
dep.as_name(),
|
||||
ModuleId { krate: dep.crate_id, module_id: dep_def_map.root }.into(),
|
||||
ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(),
|
||||
);
|
||||
|
||||
// look for the prelude
|
||||
|
@ -323,7 +323,7 @@ where
|
|||
tested_by!(glob_across_crates);
|
||||
// glob import from other crate => we can just import everything once
|
||||
let item_map = self.db.crate_def_map(m.krate);
|
||||
let scope = &item_map[m.module_id].scope;
|
||||
let scope = &item_map[m.local_id].scope;
|
||||
|
||||
// Module scoped macros is included
|
||||
let items = scope
|
||||
|
@ -337,7 +337,7 @@ where
|
|||
// glob import from same crate => we do an initial
|
||||
// import, and then need to propagate any further
|
||||
// additions
|
||||
let scope = &self.def_map[m.module_id].scope;
|
||||
let scope = &self.def_map[m.local_id].scope;
|
||||
|
||||
// Module scoped macros is included
|
||||
let items = scope
|
||||
|
@ -349,7 +349,7 @@ where
|
|||
self.update(module_id, Some(import_id), &items);
|
||||
// record the glob import in case we add further items
|
||||
self.glob_imports
|
||||
.entry(m.module_id)
|
||||
.entry(m.local_id)
|
||||
.or_default()
|
||||
.push((module_id, import_id));
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ where
|
|||
raw::RawItemKind::Impl(imp) => {
|
||||
let module = ModuleId {
|
||||
krate: self.def_collector.def_map.krate,
|
||||
module_id: self.module_id,
|
||||
local_id: self.module_id,
|
||||
};
|
||||
let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
|
||||
let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id);
|
||||
|
@ -673,7 +673,7 @@ where
|
|||
modules[self.module_id].children.insert(name.clone(), res);
|
||||
let resolution = Resolution {
|
||||
def: PerNs::types(
|
||||
ModuleId { krate: self.def_collector.def_map.krate, module_id: res }.into(),
|
||||
ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(),
|
||||
),
|
||||
import: None,
|
||||
};
|
||||
|
@ -683,7 +683,7 @@ where
|
|||
|
||||
fn define_def(&mut self, def: &raw::DefData) {
|
||||
let module =
|
||||
ModuleId { krate: self.def_collector.def_map.krate, module_id: self.module_id };
|
||||
ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
|
||||
let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
|
||||
|
||||
let name = def.name.clone();
|
||||
|
|
|
@ -74,19 +74,19 @@ impl CrateDefMap {
|
|||
PathKind::DollarCrate(krate) => {
|
||||
if krate == self.krate {
|
||||
tested_by!(macro_dollar_crate_self);
|
||||
PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into())
|
||||
PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into())
|
||||
} else {
|
||||
let def_map = db.crate_def_map(krate);
|
||||
let module = ModuleId { krate, module_id: def_map.root };
|
||||
let module = ModuleId { krate, local_id: def_map.root };
|
||||
tested_by!(macro_dollar_crate_other);
|
||||
PerNs::types(module.into())
|
||||
}
|
||||
}
|
||||
PathKind::Crate => {
|
||||
PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into())
|
||||
PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into())
|
||||
}
|
||||
PathKind::Self_ => {
|
||||
PerNs::types(ModuleId { krate: self.krate, module_id: original_module }.into())
|
||||
PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into())
|
||||
}
|
||||
// plain import or absolute path in 2015: crate-relative with
|
||||
// fallback to extern prelude (with the simplification in
|
||||
|
@ -113,7 +113,7 @@ impl CrateDefMap {
|
|||
}
|
||||
PathKind::Super => {
|
||||
if let Some(p) = self.modules[original_module].parent {
|
||||
PerNs::types(ModuleId { krate: self.krate, module_id: p }.into())
|
||||
PerNs::types(ModuleId { krate: self.krate, local_id: p }.into())
|
||||
} else {
|
||||
log::debug!("super path in root module");
|
||||
return ResolvePathResult::empty(ReachedFixedPoint::Yes);
|
||||
|
@ -160,7 +160,7 @@ impl CrateDefMap {
|
|||
Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ };
|
||||
log::debug!("resolving {:?} in other crate", path);
|
||||
let defp_map = db.crate_def_map(module.krate);
|
||||
let (def, s) = defp_map.resolve_path(db, module.module_id, &path);
|
||||
let (def, s) = defp_map.resolve_path(db, module.local_id, &path);
|
||||
return ResolvePathResult::with(
|
||||
def,
|
||||
ReachedFixedPoint::Yes,
|
||||
|
@ -169,7 +169,7 @@ impl CrateDefMap {
|
|||
}
|
||||
|
||||
// Since it is a qualified path here, it should not contains legacy macros
|
||||
match self[module.module_id].scope.get(&segment.name) {
|
||||
match self[module.local_id].scope.get(&segment.name) {
|
||||
Some(res) => res.def,
|
||||
_ => {
|
||||
log::debug!("path segment {:?} not found", segment.name);
|
||||
|
@ -254,7 +254,7 @@ impl CrateDefMap {
|
|||
keep = db.crate_def_map(prelude.krate);
|
||||
&keep
|
||||
};
|
||||
def_map[prelude.module_id].scope.get(name).map_or_else(PerNs::none, |res| res.def)
|
||||
def_map[prelude.local_id].scope.get(name).map_or_else(PerNs::none, |res| res.def)
|
||||
} else {
|
||||
PerNs::none()
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ impl Resolver {
|
|||
if let Scope::ModuleScope(m) = scope {
|
||||
if let Some(prelude) = m.crate_def_map.prelude {
|
||||
let prelude_def_map = db.crate_def_map(prelude.krate);
|
||||
traits.extend(prelude_def_map[prelude.module_id].scope.traits());
|
||||
traits.extend(prelude_def_map[prelude.local_id].scope.traits());
|
||||
}
|
||||
traits.extend(m.crate_def_map[m.module_id].scope.traits());
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ impl Scope {
|
|||
});
|
||||
if let Some(prelude) = m.crate_def_map.prelude {
|
||||
let prelude_def_map = db.crate_def_map(prelude.krate);
|
||||
prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| {
|
||||
prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, res)| {
|
||||
f(name.clone(), ScopeDef::PerNs(res.def));
|
||||
});
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ pub trait HasResolver: Copy {
|
|||
impl HasResolver for ModuleId {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
let def_map = db.crate_def_map(self.krate);
|
||||
Resolver::default().push_module_scope(def_map, self.module_id)
|
||||
Resolver::default().push_module_scope(def_map, self.local_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@ impl TestDB {
|
|||
pub fn module_for_file(&self, file_id: FileId) -> ModuleId {
|
||||
for &krate in self.relevant_crates(file_id).iter() {
|
||||
let crate_def_map = self.crate_def_map(krate);
|
||||
for (module_id, data) in crate_def_map.modules.iter() {
|
||||
for (local_id, data) in crate_def_map.modules.iter() {
|
||||
if data.definition == Some(file_id) {
|
||||
return ModuleId { krate, module_id };
|
||||
return ModuleId { krate, local_id };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4677,7 +4677,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
|
|||
|
||||
let module = db.module_for_file(pos.file_id);
|
||||
let crate_def_map = db.crate_def_map(module.krate);
|
||||
for decl in crate_def_map[module.module_id].scope.declarations() {
|
||||
for decl in crate_def_map[module.local_id].scope.declarations() {
|
||||
if let ModuleDefId::FunctionId(func) = decl {
|
||||
let (_body, source_map) = db.body_with_source_map(func.into());
|
||||
if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) {
|
||||
|
@ -4753,7 +4753,7 @@ fn infer(content: &str) -> String {
|
|||
let crate_def_map = db.crate_def_map(module.krate);
|
||||
|
||||
let mut defs: Vec<DefWithBodyId> = Vec::new();
|
||||
visit_module(&db, &crate_def_map, module.module_id, &mut |it| defs.push(it));
|
||||
visit_module(&db, &crate_def_map, module.local_id, &mut |it| defs.push(it));
|
||||
defs.sort_by_key(|def| match def {
|
||||
DefWithBodyId::FunctionId(it) => {
|
||||
it.lookup(&db).ast_id.to_node(&db).syntax().text_range().start()
|
||||
|
@ -4796,7 +4796,7 @@ fn visit_module(
|
|||
}
|
||||
}
|
||||
}
|
||||
ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.module_id, cb),
|
||||
ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.local_id, cb),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -4844,7 +4844,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
let events = db.log_executed(|| {
|
||||
let module = db.module_for_file(pos.file_id);
|
||||
let crate_def_map = db.crate_def_map(module.krate);
|
||||
visit_module(&db, &crate_def_map, module.module_id, &mut |def| {
|
||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
||||
db.infer(def);
|
||||
});
|
||||
});
|
||||
|
@ -4866,7 +4866,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
let events = db.log_executed(|| {
|
||||
let module = db.module_for_file(pos.file_id);
|
||||
let crate_def_map = db.crate_def_map(module.krate);
|
||||
visit_module(&db, &crate_def_map, module.module_id, &mut |def| {
|
||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
||||
db.infer(def);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue