From c32be4bfe8c7fd176f620c193c86ab74fa9bdee7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 28 Jan 2020 17:08:17 +0800 Subject: Ignore illform node id from metadata --- crates/ra_project_model/src/cargo_workspace.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'crates/ra_project_model') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 1832c101f..66db2be51 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -207,9 +207,25 @@ impl CargoWorkspace { } let resolve = meta.resolve.expect("metadata executed with deps"); for node in resolve.nodes { - let source = pkg_by_id[&node.id]; + let source = match pkg_by_id.get(&node.id) { + Some(&src) => src, + None => { + log::error!("Node id do not match in cargo metadata, ignoring {}", node.id); + continue; + } + }; for dep_node in node.deps { - let dep = PackageDependency { name: dep_node.name, pkg: pkg_by_id[&dep_node.pkg] }; + let pkg = match pkg_by_id.get(&dep_node.pkg) { + Some(&pkg) => pkg, + None => { + log::error!( + "Dep node id do not match in cargo metadata, ignoring {}", + dep_node.pkg + ); + continue; + } + }; + let dep = PackageDependency { name: dep_node.name, pkg }; packages[source].dependencies.push(dep); } packages[source].features.extend(node.features); -- cgit v1.2.3 From c2e3dba8cbf446a0210d6153e4a6a91fa0aac9b6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jan 2020 18:01:38 +0100 Subject: Add a FIXME note --- crates/ra_project_model/src/cargo_workspace.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crates/ra_project_model') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 66db2be51..60cb8c1eb 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -209,6 +209,9 @@ impl CargoWorkspace { for node in resolve.nodes { let source = match pkg_by_id.get(&node.id) { Some(&src) => src, + // FIXME: replace this and a similar branch below with `.unwrap`, once + // https://github.com/rust-lang/cargo/issues/7841 + // is fixed and hits stable (around 1.43-is probably?). None => { log::error!("Node id do not match in cargo metadata, ignoring {}", node.id); continue; -- cgit v1.2.3 From 78092c7c66a665ada55ea09476a387014f6665b0 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 5 Feb 2020 12:47:28 +0200 Subject: Apply the reviews suggestions --- crates/ra_project_model/src/lib.rs | 43 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'crates/ra_project_model') 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::{ }; use ra_cfg::CfgOptions; -use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; +use ra_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId}; use rustc_hash::FxHashMap; use serde_json::from_reader; @@ -177,7 +177,9 @@ impl ProjectWorkspace { if let (Some(&from), Some(&to)) = (crates.get(&from_crate_id), crates.get(&to_crate_id)) { - if let Err(_) = crate_graph.add_dep(from, dep.name.clone().into(), to) { + if let Err(_) = + crate_graph.add_dep(from, CrateName::new(&dep.name).unwrap(), to) + { log::error!( "cyclic dependency {:?} -> {:?}", from_crate_id, @@ -215,7 +217,9 @@ impl ProjectWorkspace { if let (Some(&from), Some(&to)) = (sysroot_crates.get(&from), sysroot_crates.get(&to)) { - if let Err(_) = crate_graph.add_dep(from, name.into(), to) { + if let Err(_) = + crate_graph.add_dep(from, CrateName::new(name).unwrap(), to) + { log::error!("cyclic dependency between sysroot crates") } } @@ -257,7 +261,7 @@ impl ProjectWorkspace { if let Some(proc_macro) = libproc_macro { if let Err(_) = crate_graph.add_dep( crate_id, - "proc_macro".into(), + CrateName::new("proc_macro").unwrap(), proc_macro, ) { log::error!( @@ -276,9 +280,14 @@ impl ProjectWorkspace { for &from in pkg_crates.get(&pkg).into_iter().flatten() { if let Some(to) = lib_tgt { if to != from { - if let Err(_) = - crate_graph.add_dep(from, pkg.name(&cargo).into(), to) - { + if let Err(_) = crate_graph.add_dep( + from, + // For root projects with dashes in their name, + // cargo metadata does not do any normalization, + // so we do it ourselves currently + CrateName::normalize_dashes(pkg.name(&cargo)), + to, + ) { log::error!( "cyclic dependency between targets of {}", pkg.name(&cargo) @@ -289,17 +298,23 @@ impl ProjectWorkspace { // core is added as a dependency before std in order to // mimic rustcs dependency order if let Some(core) = libcore { - if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { + if let Err(_) = + crate_graph.add_dep(from, CrateName::new("core").unwrap(), core) + { log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) } } if let Some(alloc) = liballoc { - if let Err(_) = crate_graph.add_dep(from, "alloc".into(), alloc) { + if let Err(_) = + crate_graph.add_dep(from, CrateName::new("alloc").unwrap(), alloc) + { log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) } } if let Some(std) = libstd { - if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { + if let Err(_) = + crate_graph.add_dep(from, CrateName::new("std").unwrap(), std) + { log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) } } @@ -312,9 +327,11 @@ impl ProjectWorkspace { for dep in pkg.dependencies(&cargo) { if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { for &from in pkg_crates.get(&pkg).into_iter().flatten() { - if let Err(_) = - crate_graph.add_dep(from, dep.name.clone().into(), to) - { + if let Err(_) = crate_graph.add_dep( + from, + CrateName::new(&dep.name).unwrap(), + to, + ) { log::error!( "cyclic dependency {} -> {}", pkg.name(&cargo), -- cgit v1.2.3