From 76fb73a99e2794b0e67ff279e48a3f88c193d41a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 18 Mar 2024 11:14:36 +0100 Subject: [PATCH] Skip problematic cyclic dev-dependencies --- crates/project-model/src/workspace.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 1a138b17ba..5e06010c67 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -1091,6 +1091,24 @@ fn cargo_to_crate_graph( continue; } + // If the dependency is a dev-dependency with both crates being member libraries of + // the workspace we discard the edge. The reason can be read up on in + // https://github.com/rust-lang/rust-analyzer/issues/14167 + // but in short, such an edge usually causes some form of cycle in the crate graph + // wrt to unit tests. Something we cannot reasonable support. + if dep.kind == DepKind::Dev + && matches!(kind, TargetKind::Lib { .. }) + && cargo[dep.pkg].is_member + && cargo[pkg].is_member + { + tracing::warn!( + "Discarding dev-dependency edge from library target `{}` to library target `{}` to prevent potential cycles", + cargo[dep.pkg].name, + cargo[pkg].name + ); + continue; + } + add_dep(crate_graph, from, name.clone(), to) } }