Don't load auxiliary crates outside the workspace

This commit is contained in:
Jonas Schievink 2022-01-18 18:17:43 +01:00
parent ac8806df08
commit 22ea5595a8

View file

@ -574,6 +574,15 @@ fn cargo_to_crate_graph(
has_private |= cargo[pkg].metadata.rustc_private;
let mut lib_tgt = None;
for &tgt in cargo[pkg].targets.iter() {
if cargo[tgt].kind != TargetKind::Lib && !cargo[pkg].is_member {
// For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
// add any targets except the library target, since those will not work correctly if
// they use dev-dependencies.
// In fact, they can break quite badly if multiple client workspaces get merged:
// https://github.com/rust-analyzer/rust-analyzer/issues/11300
continue;
}
if let Some(file_id) = load(&cargo[tgt].root) {
let crate_id = add_target_crate_root(
&mut crate_graph,