Skip to content

Commit 80386ca

Browse files
committed
Use Strings for display names
1 parent 307c6fe commit 80386ca

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

crates/ra_db/src/fixture.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,17 @@ fn with_files(
149149
let crate_id = crate_graph.add_crate_root(
150150
file_id,
151151
meta.edition,
152-
Some(CrateName::new(&krate).unwrap()),
152+
Some(krate.clone()),
153153
meta.cfg,
154154
meta.env,
155155
Default::default(),
156156
);
157-
let prev = crates.insert(krate.clone(), crate_id);
157+
let crate_name = CrateName::new(&krate).unwrap();
158+
let prev = crates.insert(crate_name.clone(), crate_id);
158159
assert!(prev.is_none());
159160
for dep in meta.deps {
160-
crate_deps.push((krate.clone(), dep))
161+
let dep = CrateName::new(&dep).unwrap();
162+
crate_deps.push((crate_name.clone(), dep))
161163
}
162164
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
163165
assert!(default_crate_root.is_none());

crates/ra_db/src/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct CrateGraph {
6767
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6868
pub struct CrateId(pub u32);
6969

70-
#[derive(Debug, Clone, PartialEq, Eq)]
70+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7171
pub struct CrateName(SmolStr);
7272

7373
impl CrateName {
@@ -124,7 +124,7 @@ pub struct CrateData {
124124
/// The name to display to the end user.
125125
/// This actual crate name can be different in a particular dependent crate
126126
/// or may even be missing for some cases, such as a dummy crate for the code snippet.
127-
pub display_name: Option<CrateName>,
127+
pub display_name: Option<String>,
128128
pub cfg_options: CfgOptions,
129129
pub env: Env,
130130
pub dependencies: Vec<Dependency>,
@@ -153,7 +153,7 @@ impl CrateGraph {
153153
&mut self,
154154
file_id: FileId,
155155
edition: Edition,
156-
display_name: Option<CrateName>,
156+
display_name: Option<String>,
157157
cfg_options: CfgOptions,
158158
env: Env,
159159
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,

crates/ra_hir/src/code_model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use hir_ty::{
3131
ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty,
3232
TyDefId, TypeCtor,
3333
};
34-
use ra_db::{CrateId, CrateName, Edition, FileId};
34+
use ra_db::{CrateId, Edition, FileId};
3535
use ra_prof::profile;
3636
use ra_syntax::ast::{self, AttrsOwner, NameOwner};
3737
use rustc_hash::FxHashSet;
@@ -94,8 +94,8 @@ impl Crate {
9494
db.crate_graph()[self.id].edition
9595
}
9696

97-
pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
98-
db.crate_graph()[self.id].display_name.as_ref().cloned()
97+
pub fn display_name(self, db: &dyn HirDatabase) -> Option<String> {
98+
db.crate_graph()[self.id].display_name.clone()
9999
}
100100

101101
pub fn query_external_importables(

crates/ra_ide/src/mock_analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl MockAnalysis {
130130
let other_crate = crate_graph.add_crate_root(
131131
file_id,
132132
edition,
133-
Some(CrateName::new(crate_name).unwrap()),
133+
Some(crate_name.to_string()),
134134
cfg,
135135
env,
136136
Default::default(),

crates/ra_project_model/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,11 @@ impl ProjectWorkspace {
309309

310310
let env = Env::default();
311311
let proc_macro = vec![];
312-
let crate_name = CrateName::new(&sysroot[krate].name)
313-
.expect("Sysroot crate names should not contain dashes");
314-
312+
let name = sysroot[krate].name.clone();
315313
let crate_id = crate_graph.add_crate_root(
316314
file_id,
317315
Edition::Edition2018,
318-
Some(crate_name),
316+
Some(name),
319317
cfg_options.clone(),
320318
env,
321319
proc_macro,
@@ -389,7 +387,7 @@ impl ProjectWorkspace {
389387
let crate_id = crate_graph.add_crate_root(
390388
file_id,
391389
edition,
392-
Some(CrateName::normalize_dashes(&cargo[pkg].name)),
390+
Some(cargo[pkg].name.clone()),
393391
cfg_options,
394392
env,
395393
proc_macro.clone(),

0 commit comments

Comments
 (0)