From 307c6fec618d5e509c754362687253ef44bb5f3f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 09:53:53 +0200 Subject: Use CrateName for semantic names --- crates/ra_db/src/input.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 7f3660118..a8cc588f9 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -94,6 +94,13 @@ impl fmt::Display for CrateName { } } +impl ops::Deref for CrateName { + type Target = str; + fn deref(&self) -> &Self::Target { + &*self.0 + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct ProcMacroId(pub u32); @@ -138,7 +145,7 @@ pub struct Env { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { pub crate_id: CrateId, - pub name: SmolStr, + pub name: CrateName, } impl CrateGraph { @@ -178,7 +185,7 @@ impl CrateGraph { if self.dfs_find(from, to, &mut FxHashSet::default()) { return Err(CyclicDependenciesError); } - self.arena.get_mut(&from).unwrap().add_dep(name.0, to); + self.arena.get_mut(&from).unwrap().add_dep(name, to); Ok(()) } @@ -247,7 +254,7 @@ impl CrateId { } impl CrateData { - fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { + fn add_dep(&mut self, name: CrateName, crate_id: CrateId) { self.dependencies.push(Dependency { name, crate_id }) } } @@ -429,7 +436,10 @@ mod tests { .is_ok()); assert_eq!( graph[crate1].dependencies, - vec![Dependency { crate_id: crate2, name: "crate_name_with_dashes".into() }] + vec![Dependency { + crate_id: crate2, + name: CrateName::new("crate_name_with_dashes").unwrap() + }] ); } } -- cgit v1.2.3 From 80386ca5be78d8ea65483df3edeec1a89b09a5a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 10:03:07 +0200 Subject: Use Strings for display names --- crates/ra_db/src/fixture.rs | 8 +++++--- crates/ra_db/src/input.rs | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 4f4fb4494..209713987 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -149,15 +149,17 @@ fn with_files( let crate_id = crate_graph.add_crate_root( file_id, meta.edition, - Some(CrateName::new(&krate).unwrap()), + Some(krate.clone()), meta.cfg, meta.env, Default::default(), ); - let prev = crates.insert(krate.clone(), crate_id); + let crate_name = CrateName::new(&krate).unwrap(); + let prev = crates.insert(crate_name.clone(), crate_id); assert!(prev.is_none()); for dep in meta.deps { - crate_deps.push((krate.clone(), dep)) + let dep = CrateName::new(&dep).unwrap(); + crate_deps.push((crate_name.clone(), dep)) } } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { assert!(default_crate_root.is_none()); diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a8cc588f9..445a1ee48 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -67,7 +67,7 @@ pub struct CrateGraph { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CrateId(pub u32); -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CrateName(SmolStr); impl CrateName { @@ -124,7 +124,7 @@ pub struct CrateData { /// The name to display to the end user. /// This actual crate name can be different in a particular dependent crate /// or may even be missing for some cases, such as a dummy crate for the code snippet. - pub display_name: Option, + pub display_name: Option, pub cfg_options: CfgOptions, pub env: Env, pub dependencies: Vec, @@ -153,7 +153,7 @@ impl CrateGraph { &mut self, file_id: FileId, edition: Edition, - display_name: Option, + display_name: Option, cfg_options: CfgOptions, env: Env, proc_macro: Vec<(SmolStr, Arc)>, -- cgit v1.2.3