mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
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 <edwin0cheng@gmail.com>
This commit is contained in:
commit
c7e0baf1a8
1 changed files with 18 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue