Skip to content

Commit af4e755

Browse files
committed
Rename declaration_name -> display_name
Declaration names sounds like a name of declaration -- something you can use for analysis. It empathically isn't, and is just a label displayed in various UI. It's important not to confuse the two, least we accidentally mix semantics with UI (I believe, there's already a case of this in the FamousDefs at least).
1 parent be762cc commit af4e755

File tree

11 files changed

+28
-35
lines changed

11 files changed

+28
-35
lines changed

crates/assists/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub use prelude::*;
406406
let std_crate = path.next()?;
407407
let std_crate = if self
408408
.1
409-
.declaration_name(db)
409+
.display_name(db)
410410
.map(|name| name.to_string() == std_crate)
411411
.unwrap_or(false)
412412
{

crates/base_db/src/input.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ impl PartialEq for ProcMacro {
127127
pub struct CrateData {
128128
pub root_file_id: FileId,
129129
pub edition: Edition,
130-
/// A name used in the package's project declaration: for Cargo projects, it's [package].name,
131-
/// can be different for other project types or even absent (a dummy crate for the code snippet, for example).
132-
/// NOTE: The crate can be referenced as a dependency under a different name,
133-
/// this one should be used when working with crate hierarchies.
134-
pub declaration_name: Option<CrateName>,
130+
/// A name used in the package's project declaration: for Cargo projects,
131+
/// it's [package].name, can be different for other project types or even
132+
/// absent (a dummy crate for the code snippet, for example).
133+
///
134+
/// For purposes of analysis, crates are anonymous (only names in
135+
/// `Dependency` matters), this name should only be used for UI.
136+
pub display_name: Option<CrateName>,
135137
pub cfg_options: CfgOptions,
136138
pub env: Env,
137139
pub dependencies: Vec<Dependency>,
@@ -160,7 +162,7 @@ impl CrateGraph {
160162
&mut self,
161163
file_id: FileId,
162164
edition: Edition,
163-
declaration_name: Option<CrateName>,
165+
display_name: Option<CrateName>,
164166
cfg_options: CfgOptions,
165167
env: Env,
166168
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
@@ -171,7 +173,7 @@ impl CrateGraph {
171173
let data = CrateData {
172174
root_file_id: file_id,
173175
edition,
174-
declaration_name,
176+
display_name,
175177
cfg_options,
176178
env,
177179
proc_macro,
@@ -310,8 +312,8 @@ impl CrateGraph {
310312
}
311313
}
312314

313-
fn hacky_find_crate(&self, declaration_name: &str) -> Option<CrateId> {
314-
self.iter().find(|it| self[*it].declaration_name.as_deref() == Some(declaration_name))
315+
fn hacky_find_crate(&self, display_name: &str) -> Option<CrateId> {
316+
self.iter().find(|it| self[*it].display_name.as_deref() == Some(display_name))
315317
}
316318
}
317319

crates/hir/src/code_model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ impl Crate {
103103
db.crate_graph()[self.id].edition
104104
}
105105

106-
pub fn declaration_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
107-
db.crate_graph()[self.id].declaration_name.clone()
106+
pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
107+
db.crate_graph()[self.id].display_name.clone()
108108
}
109109

110110
pub fn query_external_importables(

crates/hir_def/src/import_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ mod tests {
356356
let krate = crate_graph
357357
.iter()
358358
.find(|krate| {
359-
crate_graph[*krate].declaration_name.as_ref().map(|n| n.to_string())
359+
crate_graph[*krate].display_name.as_ref().map(|n| n.to_string())
360360
== Some(crate_name.to_string())
361361
})
362362
.unwrap();
@@ -375,7 +375,7 @@ mod tests {
375375
let path = map.path_of(item).unwrap();
376376
format!(
377377
"{}::{} ({})\n",
378-
crate_graph[krate].declaration_name.as_ref().unwrap(),
378+
crate_graph[krate].display_name.as_ref().unwrap(),
379379
path,
380380
mark
381381
)
@@ -416,7 +416,7 @@ mod tests {
416416
.iter()
417417
.filter_map(|krate| {
418418
let cdata = &crate_graph[krate];
419-
let name = cdata.declaration_name.as_ref()?;
419+
let name = cdata.display_name.as_ref()?;
420420

421421
let map = db.import_map(krate);
422422

crates/hir_def/src/nameres.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ pub struct ModuleData {
172172
impl CrateDefMap {
173173
pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
174174
let _p = profile::span("crate_def_map_query").detail(|| {
175-
db.crate_graph()[krate]
176-
.declaration_name
177-
.as_ref()
178-
.map(ToString::to_string)
179-
.unwrap_or_default()
175+
db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
180176
});
181177
let def_map = {
182178
let edition = db.crate_graph()[krate].edition;

crates/ide/src/doc_links.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
130130
let module = definition.module(db)?;
131131
let krate = module.krate();
132132
let import_map = db.import_map(krate.into());
133-
let base = once(krate.declaration_name(db)?.to_string())
133+
let base = once(krate.display_name(db)?.to_string())
134134
.chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
135135
.join("/");
136136

@@ -188,7 +188,7 @@ fn rewrite_intra_doc_link(
188188
let krate = resolved.module(db)?.krate();
189189
let canonical_path = resolved.canonical_path(db)?;
190190
let new_target = get_doc_url(db, &krate)?
191-
.join(&format!("{}/", krate.declaration_name(db)?))
191+
.join(&format!("{}/", krate.display_name(db)?))
192192
.ok()?
193193
.join(&canonical_path.replace("::", "/"))
194194
.ok()?
@@ -208,7 +208,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<S
208208
let module = def.module(db)?;
209209
let krate = module.krate();
210210
let canonical_path = def.canonical_path(db)?;
211-
let base = format!("{}/{}", krate.declaration_name(db)?, canonical_path.replace("::", "/"));
211+
let base = format!("{}/{}", krate.display_name(db)?, canonical_path.replace("::", "/"));
212212

213213
get_doc_url(db, &krate)
214214
.and_then(|url| url.join(&base).ok())
@@ -357,7 +357,7 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
357357
//
358358
// FIXME: clicking on the link should just open the file in the editor,
359359
// instead of falling back to external urls.
360-
Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?))
360+
Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?))
361361
})
362362
.and_then(|s| Url::parse(&s).ok())
363363
}

crates/ide/src/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
300300

301301
fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
302302
let crate_name =
303-
db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::to_string);
303+
db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
304304
let module_path = module
305305
.path_to_root(db)
306306
.into_iter()

crates/ide/src/inlay_hints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn hint_iterator(
215215
.last()
216216
.and_then(|strukt| strukt.as_adt())?;
217217
let krate = strukt.krate(db)?;
218-
if krate.declaration_name(db).as_deref() != Some("core") {
218+
if krate.display_name(db).as_deref() != Some("core") {
219219
return None;
220220
}
221221
let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?;

crates/ide/src/prime_caches.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress)
3232
// Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
3333
// cancellation, so we cannot use rayon.
3434
for (i, krate) in topo.iter().enumerate() {
35-
let crate_name =
36-
graph[*krate].declaration_name.as_ref().map(ToString::to_string).unwrap_or_default();
35+
let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string();
3736

3837
cb(PrimeCachesProgress::StartedOnCrate {
3938
on_crate: crate_name,

crates/ide/src/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
4545
match krate {
4646
Some(krate) => {
4747
let crate_graph = db.crate_graph();
48-
let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_name {
48+
let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
4949
Some(it) => format!("{}({:?})", it, krate),
5050
None => format!("{:?}", krate),
5151
};

0 commit comments

Comments
 (0)