aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-30 16:48:35 +0000
committerGitHub <[email protected]>2020-01-30 16:48:35 +0000
commitc7e0baf1a80dad5b7b2a819bbd426074c77be9d7 (patch)
treee8adea4706c75cdc92e6bb0073cddb9501ac1dfb
parent5f0b17b52dafa7b1eb1ba8934ce44857413410a7 (diff)
parentc32be4bfe8c7fd176f620c193c86ab74fa9bdee7 (diff)
Merge #2920
2920: Better handle illformed node id from metadata r=matklad a=edwin0cheng In some rare cases, deps node-id from cargo-metadata do not match its version-id, which cause a panic in `cargo-workspace.rs`. This PR try to ignore these ill-formed node id from `cargo-metadata`. An alternative is return `Err` in these cases but I think make it resilience is a better choice here. Related #2767 Co-authored-by: Edwin Cheng <[email protected]>
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs20
1 files 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 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 {
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 None => {
213 log::error!("Node id do not match in cargo metadata, ignoring {}", node.id);
214 continue;
215 }
216 };
211 for dep_node in node.deps { 217 for dep_node in node.deps {
212 let dep = PackageDependency { name: dep_node.name, pkg: pkg_by_id[&dep_node.pkg] }; 218 let pkg = match pkg_by_id.get(&dep_node.pkg) {
219 Some(&pkg) => pkg,
220 None => {
221 log::error!(
222 "Dep node id do not match in cargo metadata, ignoring {}",
223 dep_node.pkg
224 );
225 continue;
226 }
227 };
228 let dep = PackageDependency { name: dep_node.name, pkg };
213 packages[source].dependencies.push(dep); 229 packages[source].dependencies.push(dep);
214 } 230 }
215 packages[source].features.extend(node.features); 231 packages[source].features.extend(node.features);