about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-03-18 11:14:36 +0100
committerLukas Wirth <lukastw97@gmail.com>2024-03-18 11:25:59 +0100
commit76fb73a99e2794b0e67ff279e48a3f88c193d41a (patch)
treed6653c82d0be85941a3fea22c603f0e1eaf74b78
parentf07489ada9920c83a16a71667d4792287e137205 (diff)
downloadrust-76fb73a99e2794b0e67ff279e48a3f88c193d41a.tar.gz
rust-76fb73a99e2794b0e67ff279e48a3f88c193d41a.zip
Skip problematic cyclic dev-dependencies
-rw-r--r--crates/project-model/src/workspace.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 1a138b17bad..5e06010c678 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)
             }
         }