Skip to content

Commit d9a36a7

Browse files
committed
Rename module_id -> local_id
1 parent 47ec2ce commit d9a36a7

File tree

13 files changed

+47
-47
lines changed

13 files changed

+47
-47
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ pub use hir_def::attr::Attrs;
174174

175175
impl Module {
176176
pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module {
177-
Module { id: ModuleId { krate: krate.crate_id, module_id: crate_module_id } }
177+
Module { id: ModuleId { krate: krate.crate_id, local_id: crate_module_id } }
178178
}
179179

180180
/// Name of this module.
181181
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
182182
let def_map = db.crate_def_map(self.id.krate);
183-
let parent = def_map[self.id.module_id].parent?;
183+
let parent = def_map[self.id.local_id].parent?;
184184
def_map[parent].children.iter().find_map(|(name, module_id)| {
185-
if *module_id == self.id.module_id {
185+
if *module_id == self.id.local_id {
186186
Some(name.clone())
187187
} else {
188188
None
@@ -206,14 +206,14 @@ impl Module {
206206
/// Finds a child module with the specified name.
207207
pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> {
208208
let def_map = db.crate_def_map(self.id.krate);
209-
let child_id = def_map[self.id.module_id].children.get(name)?;
209+
let child_id = def_map[self.id.local_id].children.get(name)?;
210210
Some(self.with_module_id(*child_id))
211211
}
212212

213213
/// Iterates over all child modules.
214214
pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
215215
let def_map = db.crate_def_map(self.id.krate);
216-
let children = def_map[self.id.module_id]
216+
let children = def_map[self.id.local_id]
217217
.children
218218
.iter()
219219
.map(|(_, module_id)| self.with_module_id(*module_id))
@@ -224,7 +224,7 @@ impl Module {
224224
/// Finds a parent module.
225225
pub fn parent(self, db: &impl DefDatabase) -> Option<Module> {
226226
let def_map = db.crate_def_map(self.id.krate);
227-
let parent_id = def_map[self.id.module_id].parent?;
227+
let parent_id = def_map[self.id.local_id].parent?;
228228
Some(self.with_module_id(parent_id))
229229
}
230230

@@ -240,7 +240,7 @@ impl Module {
240240

241241
/// Returns a `ModuleScope`: a set of items, visible in this module.
242242
pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> {
243-
db.crate_def_map(self.id.krate)[self.id.module_id]
243+
db.crate_def_map(self.id.krate)[self.id.local_id]
244244
.scope
245245
.entries()
246246
.map(|(name, res)| {
@@ -250,7 +250,7 @@ impl Module {
250250
}
251251

252252
pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
253-
db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.module_id, sink);
253+
db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink);
254254
for decl in self.declarations(db) {
255255
match decl {
256256
crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
@@ -275,12 +275,12 @@ impl Module {
275275

276276
pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
277277
let def_map = db.crate_def_map(self.id.krate);
278-
def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect()
278+
def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect()
279279
}
280280

281281
pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
282282
let def_map = db.crate_def_map(self.id.krate);
283-
def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect()
283+
def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect()
284284
}
285285

286286
fn with_module_id(self, module_id: LocalModuleId) -> Module {

crates/ra_hir/src/code_model/src.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Module {
2222
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
2323
pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> {
2424
let def_map = db.crate_def_map(self.id.krate);
25-
let src = def_map[self.id.module_id].definition_source(db);
25+
let src = def_map[self.id.local_id].definition_source(db);
2626
src.map(|it| match it {
2727
Either::A(it) => ModuleSource::SourceFile(it),
2828
Either::B(it) => ModuleSource::Module(it),
@@ -33,7 +33,7 @@ impl Module {
3333
/// `None` for the crate root.
3434
pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
3535
let def_map = db.crate_def_map(self.id.krate);
36-
def_map[self.id.module_id].declaration_source(db)
36+
def_map[self.id.local_id].declaration_source(db)
3737
}
3838
}
3939

crates/ra_hir/src/from_source.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ impl Module {
262262

263263
let original_file = src.file_id.original_file(db);
264264

265-
let (krate, module_id) =
265+
let (krate, local_id) =
266266
db.relevant_crates(original_file).iter().find_map(|&crate_id| {
267267
let crate_def_map = db.crate_def_map(crate_id);
268-
let local_module_id = crate_def_map.modules_for_file(original_file).next()?;
269-
Some((crate_id, local_module_id))
268+
let local_id = crate_def_map.modules_for_file(original_file).next()?;
269+
Some((crate_id, local_id))
270270
})?;
271-
Some(Module { id: ModuleId { krate, module_id } })
271+
Some(Module { id: ModuleId { krate, local_id } })
272272
}
273273
}
274274

crates/ra_hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Attrs {
3535
match def {
3636
AttrDefId::ModuleId(module) => {
3737
let def_map = db.crate_def_map(module.krate);
38-
let src = match def_map[module.module_id].declaration_source(db) {
38+
let src = match def_map[module.local_id].declaration_source(db) {
3939
Some(it) => it,
4040
None => return Attrs::default(),
4141
};

crates/ra_hir_def/src/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Expander {
8282
}
8383

8484
fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
85-
self.crate_def_map.resolve_path(db, self.module.module_id, path).0.take_macros()
85+
self.crate_def_map.resolve_path(db, self.module.local_id, path).0.take_macros()
8686
}
8787
}
8888

crates/ra_hir_def/src/docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Documentation {
3636
match def {
3737
AttrDefId::ModuleId(module) => {
3838
let def_map = db.crate_def_map(module.krate);
39-
let src = def_map[module.module_id].declaration_source(db)?;
39+
let src = def_map[module.local_id].declaration_source(db)?;
4040
docs_from_ast(&src.value)
4141
}
4242
AttrDefId::StructFieldId(it) => {

crates/ra_hir_def/src/lang_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl LangItems {
4141
crate_def_map
4242
.modules
4343
.iter()
44-
.filter_map(|(module_id, _)| db.module_lang_items(ModuleId { krate, module_id }))
44+
.filter_map(|(local_id, _)| db.module_lang_items(ModuleId { krate, local_id }))
4545
.for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v))));
4646

4747
Arc::new(lang_items)
@@ -80,7 +80,7 @@ impl LangItems {
8080
fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) {
8181
// Look for impl targets
8282
let def_map = db.crate_def_map(module.krate);
83-
let module_data = &def_map[module.module_id];
83+
let module_data = &def_map[module.local_id];
8484
for &impl_block in module_data.impls.iter() {
8585
self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId)
8686
}

crates/ra_hir_def/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl_arena_id!(LocalImportId);
5050
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5151
pub struct ModuleId {
5252
pub krate: CrateId,
53-
pub module_id: LocalModuleId,
53+
pub local_id: LocalModuleId,
5454
}
5555

5656
/// An ID of a module, **local** to a specific crate

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
3737
log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
3838
def_map.extern_prelude.insert(
3939
dep.as_name(),
40-
ModuleId { krate: dep.crate_id, module_id: dep_def_map.root }.into(),
40+
ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(),
4141
);
4242

4343
// look for the prelude
@@ -323,7 +323,7 @@ where
323323
tested_by!(glob_across_crates);
324324
// glob import from other crate => we can just import everything once
325325
let item_map = self.db.crate_def_map(m.krate);
326-
let scope = &item_map[m.module_id].scope;
326+
let scope = &item_map[m.local_id].scope;
327327

328328
// Module scoped macros is included
329329
let items = scope
@@ -337,7 +337,7 @@ where
337337
// glob import from same crate => we do an initial
338338
// import, and then need to propagate any further
339339
// additions
340-
let scope = &self.def_map[m.module_id].scope;
340+
let scope = &self.def_map[m.local_id].scope;
341341

342342
// Module scoped macros is included
343343
let items = scope
@@ -349,7 +349,7 @@ where
349349
self.update(module_id, Some(import_id), &items);
350350
// record the glob import in case we add further items
351351
self.glob_imports
352-
.entry(m.module_id)
352+
.entry(m.local_id)
353353
.or_default()
354354
.push((module_id, import_id));
355355
}
@@ -590,7 +590,7 @@ where
590590
raw::RawItemKind::Impl(imp) => {
591591
let module = ModuleId {
592592
krate: self.def_collector.def_map.krate,
593-
module_id: self.module_id,
593+
local_id: self.module_id,
594594
};
595595
let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
596596
let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id);
@@ -673,7 +673,7 @@ where
673673
modules[self.module_id].children.insert(name.clone(), res);
674674
let resolution = Resolution {
675675
def: PerNs::types(
676-
ModuleId { krate: self.def_collector.def_map.krate, module_id: res }.into(),
676+
ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(),
677677
),
678678
import: None,
679679
};
@@ -683,7 +683,7 @@ where
683683

684684
fn define_def(&mut self, def: &raw::DefData) {
685685
let module =
686-
ModuleId { krate: self.def_collector.def_map.krate, module_id: self.module_id };
686+
ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
687687
let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
688688

689689
let name = def.name.clone();

crates/ra_hir_def/src/nameres/path_resolution.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ impl CrateDefMap {
7474
PathKind::DollarCrate(krate) => {
7575
if krate == self.krate {
7676
tested_by!(macro_dollar_crate_self);
77-
PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into())
77+
PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into())
7878
} else {
7979
let def_map = db.crate_def_map(krate);
80-
let module = ModuleId { krate, module_id: def_map.root };
80+
let module = ModuleId { krate, local_id: def_map.root };
8181
tested_by!(macro_dollar_crate_other);
8282
PerNs::types(module.into())
8383
}
8484
}
8585
PathKind::Crate => {
86-
PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into())
86+
PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into())
8787
}
8888
PathKind::Self_ => {
89-
PerNs::types(ModuleId { krate: self.krate, module_id: original_module }.into())
89+
PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into())
9090
}
9191
// plain import or absolute path in 2015: crate-relative with
9292
// fallback to extern prelude (with the simplification in
@@ -113,7 +113,7 @@ impl CrateDefMap {
113113
}
114114
PathKind::Super => {
115115
if let Some(p) = self.modules[original_module].parent {
116-
PerNs::types(ModuleId { krate: self.krate, module_id: p }.into())
116+
PerNs::types(ModuleId { krate: self.krate, local_id: p }.into())
117117
} else {
118118
log::debug!("super path in root module");
119119
return ResolvePathResult::empty(ReachedFixedPoint::Yes);
@@ -160,7 +160,7 @@ impl CrateDefMap {
160160
Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ };
161161
log::debug!("resolving {:?} in other crate", path);
162162
let defp_map = db.crate_def_map(module.krate);
163-
let (def, s) = defp_map.resolve_path(db, module.module_id, &path);
163+
let (def, s) = defp_map.resolve_path(db, module.local_id, &path);
164164
return ResolvePathResult::with(
165165
def,
166166
ReachedFixedPoint::Yes,
@@ -169,7 +169,7 @@ impl CrateDefMap {
169169
}
170170

171171
// Since it is a qualified path here, it should not contains legacy macros
172-
match self[module.module_id].scope.get(&segment.name) {
172+
match self[module.local_id].scope.get(&segment.name) {
173173
Some(res) => res.def,
174174
_ => {
175175
log::debug!("path segment {:?} not found", segment.name);
@@ -254,7 +254,7 @@ impl CrateDefMap {
254254
keep = db.crate_def_map(prelude.krate);
255255
&keep
256256
};
257-
def_map[prelude.module_id].scope.get(name).map_or_else(PerNs::none, |res| res.def)
257+
def_map[prelude.local_id].scope.get(name).map_or_else(PerNs::none, |res| res.def)
258258
} else {
259259
PerNs::none()
260260
}

0 commit comments

Comments
 (0)