From c32be4bfe8c7fd176f620c193c86ab74fa9bdee7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 28 Jan 2020 17:08:17 +0800 Subject: [PATCH] Ignore illform node id from metadata --- .../ra_project_model/src/cargo_workspace.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 1832c101f09..66db2be5199 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -207,9 +207,25 @@ pub fn from_cargo_metadata( } 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);