Skip to content

fix: Skip problematic cyclic dev-dependencies #16871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down