Skip to content

Commit 57a82fb

Browse files
Rename CrateDefMap to DefMap
1 parent 08efb8a commit 57a82fb

File tree

10 files changed

+35
-39
lines changed

10 files changed

+35
-39
lines changed

crates/hir_def/src/body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{
2929
expr::{Expr, ExprId, Label, LabelId, Pat, PatId},
3030
item_scope::BuiltinShadowMode,
3131
item_scope::ItemScope,
32-
nameres::CrateDefMap,
32+
nameres::DefMap,
3333
path::{ModPath, Path},
3434
src::HasSource,
3535
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
@@ -45,7 +45,7 @@ pub(crate) struct CfgExpander {
4545

4646
pub(crate) struct Expander {
4747
cfg_expander: CfgExpander,
48-
crate_def_map: Arc<CrateDefMap>,
48+
crate_def_map: Arc<DefMap>,
4949
current_file_id: HirFileId,
5050
ast_id_map: Arc<AstIdMap>,
5151
module: ModuleId,

crates/hir_def/src/db.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
import_map::ImportMap,
1616
item_tree::ItemTree,
1717
lang_item::{LangItemTarget, LangItems},
18-
nameres::CrateDefMap,
18+
nameres::DefMap,
1919
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
2020
GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId, StaticLoc, StructId,
2121
StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
@@ -50,10 +50,10 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
5050

5151
#[salsa::invoke(crate_def_map_wait)]
5252
#[salsa::transparent]
53-
fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
53+
fn crate_def_map(&self, krate: CrateId) -> Arc<DefMap>;
5454

55-
#[salsa::invoke(CrateDefMap::crate_def_map_query)]
56-
fn crate_def_map_query(&self, krate: CrateId) -> Arc<CrateDefMap>;
55+
#[salsa::invoke(DefMap::crate_def_map_query)]
56+
fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
5757

5858
#[salsa::invoke(StructData::struct_data_query)]
5959
fn struct_data(&self, id: StructId) -> Arc<StructData>;
@@ -112,7 +112,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
112112
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
113113
}
114114

115-
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
115+
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<DefMap> {
116116
let _p = profile::span("crate_def_map:wait");
117117
db.crate_def_map_query(krate)
118118
}

crates/hir_def/src/find_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use hir_expand::name::{known, AsName, Name};
44
use rustc_hash::FxHashSet;
55
use test_utils::mark;
66

7-
use crate::nameres::CrateDefMap;
7+
use crate::nameres::DefMap;
88
use crate::{
99
db::DefDatabase,
1010
item_scope::ItemInNs,
@@ -47,7 +47,7 @@ impl ModPath {
4747
}
4848
}
4949

50-
fn check_self_super(def_map: &CrateDefMap, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
50+
fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
5151
if item == ItemInNs::Types(from.into()) {
5252
// - if the item is the module we're in, use `self`
5353
Some(ModPath::from_segments(PathKind::Super(0), Vec::new()))

crates/hir_def/src/nameres.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use crate::{
7474

7575
/// Contains all top-level defs from a macro-expanded crate
7676
#[derive(Debug, PartialEq, Eq)]
77-
pub struct CrateDefMap {
77+
pub struct DefMap {
7878
pub root: LocalModuleId,
7979
pub modules: Arena<ModuleData>,
8080
pub(crate) krate: CrateId,
@@ -88,7 +88,7 @@ pub struct CrateDefMap {
8888
diagnostics: Vec<DefDiagnostic>,
8989
}
9090

91-
impl std::ops::Index<LocalModuleId> for CrateDefMap {
91+
impl std::ops::Index<LocalModuleId> for DefMap {
9292
type Output = ModuleData;
9393
fn index(&self, id: LocalModuleId) -> &ModuleData {
9494
&self.modules[id]
@@ -169,16 +169,16 @@ pub struct ModuleData {
169169
pub origin: ModuleOrigin,
170170
}
171171

172-
impl CrateDefMap {
173-
pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
172+
impl DefMap {
173+
pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
174174
let _p = profile::span("crate_def_map_query").detail(|| {
175175
db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
176176
});
177177
let def_map = {
178178
let edition = db.crate_graph()[krate].edition;
179179
let mut modules: Arena<ModuleData> = Arena::default();
180180
let root = modules.alloc(ModuleData::default());
181-
CrateDefMap {
181+
DefMap {
182182
krate,
183183
edition,
184184
extern_prelude: FxHashMap::default(),
@@ -227,7 +227,7 @@ impl CrateDefMap {
227227
go(&mut buf, self, "crate", self.root);
228228
return buf;
229229

230-
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
230+
fn go(buf: &mut String, map: &DefMap, path: &str, module: LocalModuleId) {
231231
format_to!(buf, "{}\n", path);
232232

233233
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();

crates/hir_def/src/nameres/collector.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
},
3232
nameres::{
3333
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
34-
BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
34+
BuiltinShadowMode, DefMap, ModuleData, ModuleOrigin, ResolveMode,
3535
},
3636
path::{ImportAlias, ModPath, PathKind},
3737
per_ns::PerNs,
@@ -45,7 +45,7 @@ const GLOB_RECURSION_LIMIT: usize = 100;
4545
const EXPANSION_DEPTH_LIMIT: usize = 128;
4646
const FIXED_POINT_LIMIT: usize = 8192;
4747

48-
pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
48+
pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap) -> DefMap {
4949
let crate_graph = db.crate_graph();
5050

5151
// populate external prelude
@@ -210,7 +210,7 @@ struct DefData<'a> {
210210
/// Walks the tree of module recursively
211211
struct DefCollector<'a> {
212212
db: &'a dyn DefDatabase,
213-
def_map: CrateDefMap,
213+
def_map: DefMap,
214214
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
215215
unresolved_imports: Vec<ImportDirective>,
216216
resolved_imports: Vec<ImportDirective>,
@@ -859,7 +859,7 @@ impl DefCollector<'_> {
859859
.collect(item_tree.top_level_items());
860860
}
861861

862-
fn finish(mut self) -> CrateDefMap {
862+
fn finish(mut self) -> DefMap {
863863
// Emit diagnostics for all remaining unexpanded macros.
864864

865865
for directive in &self.unexpanded_macros {
@@ -1474,7 +1474,7 @@ mod tests {
14741474

14751475
use super::*;
14761476

1477-
fn do_collect_defs(db: &dyn DefDatabase, def_map: CrateDefMap) -> CrateDefMap {
1477+
fn do_collect_defs(db: &dyn DefDatabase, def_map: DefMap) -> DefMap {
14781478
let mut collector = DefCollector {
14791479
db,
14801480
def_map,
@@ -1493,15 +1493,15 @@ mod tests {
14931493
collector.def_map
14941494
}
14951495

1496-
fn do_resolve(code: &str) -> CrateDefMap {
1496+
fn do_resolve(code: &str) -> DefMap {
14971497
let (db, _file_id) = TestDB::with_single_file(&code);
14981498
let krate = db.test_crate();
14991499

15001500
let def_map = {
15011501
let edition = db.crate_graph()[krate].edition;
15021502
let mut modules: Arena<ModuleData> = Arena::default();
15031503
let root = modules.alloc(ModuleData::default());
1504-
CrateDefMap {
1504+
DefMap {
15051505
krate,
15061506
edition,
15071507
extern_prelude: FxHashMap::default(),

crates/hir_def/src/nameres/path_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use test_utils::mark;
1919
use crate::{
2020
db::DefDatabase,
2121
item_scope::BUILTIN_SCOPE,
22-
nameres::{BuiltinShadowMode, CrateDefMap},
22+
nameres::{BuiltinShadowMode, DefMap},
2323
path::{ModPath, PathKind},
2424
per_ns::PerNs,
2525
visibility::{RawVisibility, Visibility},
@@ -61,7 +61,7 @@ impl ResolvePathResult {
6161
}
6262
}
6363

64-
impl CrateDefMap {
64+
impl DefMap {
6565
pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
6666
self.extern_prelude
6767
.get(name)

crates/hir_def/src/nameres/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use test_utils::mark;
1313

1414
use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
1515

16-
fn compute_crate_def_map(ra_fixture: &str) -> Arc<CrateDefMap> {
16+
fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
1717
let db = TestDB::with_files(ra_fixture);
1818
let krate = db.crate_graph().iter().next().unwrap();
1919
db.crate_def_map(krate)

crates/hir_def/src/resolver.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
expr::{ExprId, PatId},
1717
generics::GenericParams,
1818
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
19-
nameres::CrateDefMap,
19+
nameres::DefMap,
2020
path::{ModPath, PathKind},
2121
per_ns::PerNs,
2222
visibility::{RawVisibility, Visibility},
@@ -34,7 +34,7 @@ pub struct Resolver {
3434
// FIXME how to store these best
3535
#[derive(Debug, Clone)]
3636
struct ModuleItemMap {
37-
crate_def_map: Arc<CrateDefMap>,
37+
crate_def_map: Arc<DefMap>,
3838
module_id: LocalModuleId,
3939
}
4040

@@ -425,7 +425,7 @@ impl Resolver {
425425
traits
426426
}
427427

428-
fn module_scope(&self) -> Option<(&CrateDefMap, LocalModuleId)> {
428+
fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> {
429429
self.scopes.iter().rev().find_map(|scope| match scope {
430430
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
431431

@@ -588,11 +588,7 @@ impl Resolver {
588588
self.push_scope(Scope::ImplDefScope(impl_def))
589589
}
590590

591-
fn push_module_scope(
592-
self,
593-
crate_def_map: Arc<CrateDefMap>,
594-
module_id: LocalModuleId,
595-
) -> Resolver {
591+
fn push_module_scope(self, crate_def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
596592
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
597593
}
598594

crates/hir_def/src/visibility.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::ast;
55

66
use crate::{
77
db::DefDatabase,
8-
nameres::CrateDefMap,
8+
nameres::DefMap,
99
path::{ModPath, PathKind},
1010
ModuleId,
1111
};
@@ -116,7 +116,7 @@ impl Visibility {
116116

117117
pub(crate) fn is_visible_from_def_map(
118118
self,
119-
def_map: &CrateDefMap,
119+
def_map: &DefMap,
120120
from_module: crate::LocalModuleId,
121121
) -> bool {
122122
let to_module = match self {
@@ -135,7 +135,7 @@ impl Visibility {
135135
///
136136
/// If there is no subset relation between `self` and `other`, returns `None` (ie. they're only
137137
/// visible in unrelated modules).
138-
pub(crate) fn max(self, other: Visibility, def_map: &CrateDefMap) -> Option<Visibility> {
138+
pub(crate) fn max(self, other: Visibility, def_map: &DefMap) -> Option<Visibility> {
139139
match (self, other) {
140140
(Visibility::Module(_), Visibility::Public)
141141
| (Visibility::Public, Visibility::Module(_))

crates/hir_ty/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hir_def::{
1818
db::DefDatabase,
1919
item_scope::ItemScope,
2020
keys,
21-
nameres::CrateDefMap,
21+
nameres::DefMap,
2222
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
2323
};
2424
use hir_expand::{db::AstDatabase, InFile};
@@ -221,7 +221,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
221221

222222
fn visit_module(
223223
db: &TestDB,
224-
crate_def_map: &CrateDefMap,
224+
crate_def_map: &DefMap,
225225
module_id: LocalModuleId,
226226
cb: &mut dyn FnMut(DefWithBodyId),
227227
) {
@@ -249,7 +249,7 @@ fn visit_module(
249249

250250
fn visit_scope(
251251
db: &TestDB,
252-
crate_def_map: &CrateDefMap,
252+
crate_def_map: &DefMap,
253253
scope: &ItemScope,
254254
cb: &mut dyn FnMut(DefWithBodyId),
255255
) {

0 commit comments

Comments
 (0)