aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs23
-rw-r--r--crates/ra_project_model/src/lib.rs43
2 files changed, 51 insertions, 15 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 1832c101f..60cb8c1eb 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -207,9 +207,28 @@ impl CargoWorkspace {
207 } 207 }
208 let resolve = meta.resolve.expect("metadata executed with deps"); 208 let resolve = meta.resolve.expect("metadata executed with deps");
209 for node in resolve.nodes { 209 for node in resolve.nodes {
210 let source = pkg_by_id[&node.id]; 210 let source = match pkg_by_id.get(&node.id) {
211 Some(&src) => src,
212 // FIXME: replace this and a similar branch below with `.unwrap`, once
213 // https://github.com/rust-lang/cargo/issues/7841
214 // is fixed and hits stable (around 1.43-is probably?).
215 None => {
216 log::error!("Node id do not match in cargo metadata, ignoring {}", node.id);
217 continue;
218 }
219 };
211 for dep_node in node.deps { 220 for dep_node in node.deps {
212 let dep = PackageDependency { name: dep_node.name, pkg: pkg_by_id[&dep_node.pkg] }; 221 let pkg = match pkg_by_id.get(&dep_node.pkg) {
222 Some(&pkg) => pkg,
223 None => {
224 log::error!(
225 "Dep node id do not match in cargo metadata, ignoring {}",
226 dep_node.pkg
227 );
228 continue;
229 }
230 };
231 let dep = PackageDependency { name: dep_node.name, pkg };
213 packages[source].dependencies.push(dep); 232 packages[source].dependencies.push(dep);
214 } 233 }
215 packages[source].features.extend(node.features); 234 packages[source].features.extend(node.features);
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 6a104e6f2..bc1d15406 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -13,7 +13,7 @@ use std::{
13}; 13};
14 14
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; 16use ra_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use serde_json::from_reader; 18use serde_json::from_reader;
19 19
@@ -177,7 +177,9 @@ impl ProjectWorkspace {
177 if let (Some(&from), Some(&to)) = 177 if let (Some(&from), Some(&to)) =
178 (crates.get(&from_crate_id), crates.get(&to_crate_id)) 178 (crates.get(&from_crate_id), crates.get(&to_crate_id))
179 { 179 {
180 if let Err(_) = crate_graph.add_dep(from, dep.name.clone().into(), to) { 180 if let Err(_) =
181 crate_graph.add_dep(from, CrateName::new(&dep.name).unwrap(), to)
182 {
181 log::error!( 183 log::error!(
182 "cyclic dependency {:?} -> {:?}", 184 "cyclic dependency {:?} -> {:?}",
183 from_crate_id, 185 from_crate_id,
@@ -215,7 +217,9 @@ impl ProjectWorkspace {
215 if let (Some(&from), Some(&to)) = 217 if let (Some(&from), Some(&to)) =
216 (sysroot_crates.get(&from), sysroot_crates.get(&to)) 218 (sysroot_crates.get(&from), sysroot_crates.get(&to))
217 { 219 {
218 if let Err(_) = crate_graph.add_dep(from, name.into(), to) { 220 if let Err(_) =
221 crate_graph.add_dep(from, CrateName::new(name).unwrap(), to)
222 {
219 log::error!("cyclic dependency between sysroot crates") 223 log::error!("cyclic dependency between sysroot crates")
220 } 224 }
221 } 225 }
@@ -257,7 +261,7 @@ impl ProjectWorkspace {
257 if let Some(proc_macro) = libproc_macro { 261 if let Some(proc_macro) = libproc_macro {
258 if let Err(_) = crate_graph.add_dep( 262 if let Err(_) = crate_graph.add_dep(
259 crate_id, 263 crate_id,
260 "proc_macro".into(), 264 CrateName::new("proc_macro").unwrap(),
261 proc_macro, 265 proc_macro,
262 ) { 266 ) {
263 log::error!( 267 log::error!(
@@ -276,9 +280,14 @@ impl ProjectWorkspace {
276 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 280 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
277 if let Some(to) = lib_tgt { 281 if let Some(to) = lib_tgt {
278 if to != from { 282 if to != from {
279 if let Err(_) = 283 if let Err(_) = crate_graph.add_dep(
280 crate_graph.add_dep(from, pkg.name(&cargo).into(), to) 284 from,
281 { 285 // For root projects with dashes in their name,
286 // cargo metadata does not do any normalization,
287 // so we do it ourselves currently
288 CrateName::normalize_dashes(pkg.name(&cargo)),
289 to,
290 ) {
282 log::error!( 291 log::error!(
283 "cyclic dependency between targets of {}", 292 "cyclic dependency between targets of {}",
284 pkg.name(&cargo) 293 pkg.name(&cargo)
@@ -289,17 +298,23 @@ impl ProjectWorkspace {
289 // core is added as a dependency before std in order to 298 // core is added as a dependency before std in order to
290 // mimic rustcs dependency order 299 // mimic rustcs dependency order
291 if let Some(core) = libcore { 300 if let Some(core) = libcore {
292 if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { 301 if let Err(_) =
302 crate_graph.add_dep(from, CrateName::new("core").unwrap(), core)
303 {
293 log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) 304 log::error!("cyclic dependency on core for {}", pkg.name(&cargo))
294 } 305 }
295 } 306 }
296 if let Some(alloc) = liballoc { 307 if let Some(alloc) = liballoc {
297 if let Err(_) = crate_graph.add_dep(from, "alloc".into(), alloc) { 308 if let Err(_) =
309 crate_graph.add_dep(from, CrateName::new("alloc").unwrap(), alloc)
310 {
298 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) 311 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo))
299 } 312 }
300 } 313 }
301 if let Some(std) = libstd { 314 if let Some(std) = libstd {
302 if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { 315 if let Err(_) =
316 crate_graph.add_dep(from, CrateName::new("std").unwrap(), std)
317 {
303 log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) 318 log::error!("cyclic dependency on std for {}", pkg.name(&cargo))
304 } 319 }
305 } 320 }
@@ -312,9 +327,11 @@ impl ProjectWorkspace {
312 for dep in pkg.dependencies(&cargo) { 327 for dep in pkg.dependencies(&cargo) {
313 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { 328 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
314 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 329 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
315 if let Err(_) = 330 if let Err(_) = crate_graph.add_dep(
316 crate_graph.add_dep(from, dep.name.clone().into(), to) 331 from,
317 { 332 CrateName::new(&dep.name).unwrap(),
333 to,
334 ) {
318 log::error!( 335 log::error!(
319 "cyclic dependency {} -> {}", 336 "cyclic dependency {} -> {}",
320 pkg.name(&cargo), 337 pkg.name(&cargo),