From 77f67ca7e2caac6d94215834981ae3f6fb908443 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jan 2019 12:27:26 +0300 Subject: gracefully handle cycles in crate graph rust-lang/rust has absolutely weird setup with rustc-workspace-shim, which leads to real cycles. --- crates/ra_lsp_server/src/server_world.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 4f3c231d3..d5dbf999f 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -73,7 +73,9 @@ impl ServerWorldState { if let (Some(&from), Some(&to)) = (sysroot_crates.get(&from), sysroot_crates.get(&to)) { - crate_graph.add_dep(from, name.clone(), to); + if let Err(_) = crate_graph.add_dep(from, name.clone(), to) { + log::error!("cyclic dependency between sysroot crates") + } } } } @@ -108,11 +110,20 @@ impl ServerWorldState { for &from in pkg_crates.get(&pkg).into_iter().flatten() { if let Some(to) = lib_tgt { if to != from { - crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to); + if let Err(_) = + crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to) + { + log::error!( + "cyclic dependency between targets of {}", + pkg.name(&ws.cargo) + ) + } } } if let Some(std) = libstd { - crate_graph.add_dep(from, "std".into(), std); + if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { + log::error!("cyclic dependency on std for {}", pkg.name(&ws.cargo)) + } } } } @@ -123,7 +134,13 @@ impl ServerWorldState { for dep in pkg.dependencies(&ws.cargo) { if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { for &from in pkg_crates.get(&pkg).into_iter().flatten() { - crate_graph.add_dep(from, dep.name.clone(), to); + if let Err(_) = crate_graph.add_dep(from, dep.name.clone(), to) { + log::error!( + "cyclic dependency {} -> {}", + pkg.name(&ws.cargo), + dep.pkg.name(&ws.cargo) + ) + } } } } -- cgit v1.2.3