aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/lib.rs13
-rw-r--r--crates/ra_project_model/src/project_json.rs17
2 files changed, 17 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 8b85b4831..8dbf4e6ea 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -288,10 +288,7 @@ impl ProjectWorkspace {
288 if let (Some(&from), Some(&to)) = 288 if let (Some(&from), Some(&to)) =
289 (crates.get(&from_crate_id), crates.get(&to_crate_id)) 289 (crates.get(&from_crate_id), crates.get(&to_crate_id))
290 { 290 {
291 if crate_graph 291 if crate_graph.add_dep(from, dep.name.clone(), to).is_err() {
292 .add_dep(from, CrateName::new(&dep.name).unwrap(), to)
293 .is_err()
294 {
295 log::error!( 292 log::error!(
296 "cyclic dependency {:?} -> {:?}", 293 "cyclic dependency {:?} -> {:?}",
297 from_crate_id, 294 from_crate_id,
@@ -312,13 +309,11 @@ impl ProjectWorkspace {
312 309
313 let env = Env::default(); 310 let env = Env::default();
314 let proc_macro = vec![]; 311 let proc_macro = vec![];
315 let crate_name = CrateName::new(&sysroot[krate].name) 312 let name = sysroot[krate].name.clone();
316 .expect("Sysroot crate names should not contain dashes");
317
318 let crate_id = crate_graph.add_crate_root( 313 let crate_id = crate_graph.add_crate_root(
319 file_id, 314 file_id,
320 Edition::Edition2018, 315 Edition::Edition2018,
321 Some(crate_name), 316 Some(name),
322 cfg_options.clone(), 317 cfg_options.clone(),
323 env, 318 env,
324 proc_macro, 319 proc_macro,
@@ -392,7 +387,7 @@ impl ProjectWorkspace {
392 let crate_id = crate_graph.add_crate_root( 387 let crate_id = crate_graph.add_crate_root(
393 file_id, 388 file_id,
394 edition, 389 edition,
395 Some(CrateName::normalize_dashes(&cargo[pkg].name)), 390 Some(cargo[pkg].name.clone()),
396 cfg_options, 391 cfg_options,
397 env, 392 env,
398 proc_macro.clone(), 393 proc_macro.clone(),
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs
index 4b5dcd634..9fe1e2dcb 100644
--- a/crates/ra_project_model/src/project_json.rs
+++ b/crates/ra_project_model/src/project_json.rs
@@ -4,9 +4,9 @@ use std::path::PathBuf;
4 4
5use paths::{AbsPath, AbsPathBuf}; 5use paths::{AbsPath, AbsPathBuf};
6use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
7use ra_db::{CrateId, Dependency, Edition}; 7use ra_db::{CrateId, CrateName, Dependency, Edition};
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9use serde::Deserialize; 9use serde::{de, Deserialize};
10use stdx::split_delim; 10use stdx::split_delim;
11 11
12/// Roots and crates that compose this Rust project. 12/// Roots and crates that compose this Rust project.
@@ -50,7 +50,7 @@ impl ProjectJson {
50 .into_iter() 50 .into_iter()
51 .map(|dep_data| Dependency { 51 .map(|dep_data| Dependency {
52 crate_id: CrateId(dep_data.krate as u32), 52 crate_id: CrateId(dep_data.krate as u32),
53 name: dep_data.name.into(), 53 name: dep_data.name,
54 }) 54 })
55 .collect::<Vec<_>>(), 55 .collect::<Vec<_>>(),
56 cfg: { 56 cfg: {
@@ -113,5 +113,14 @@ struct DepData {
113 /// Identifies a crate by position in the crates array. 113 /// Identifies a crate by position in the crates array.
114 #[serde(rename = "crate")] 114 #[serde(rename = "crate")]
115 krate: usize, 115 krate: usize,
116 name: String, 116 #[serde(deserialize_with = "deserialize_crate_name")]
117 name: CrateName,
118}
119
120fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error>
121where
122 D: de::Deserializer<'de>,
123{
124 let name = String::deserialize(de)?;
125 CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {:?}", err)))
117} 126}