Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 98a5811

Browse files
committed
Only apply cfg(test) for local crates
Don't analyze dependencies with `test`; this should fix various cases where crates use `cfg(not(test))` and so we didn't find things. "Local" here currently means anything that's not from the registry, so anything inside the workspace, but also path dependencies. So this isn't perfect, and users might still need to use `rust-analyzer.cargo.unsetTest` for these in some cases.
1 parent 427061d commit 98a5811

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/project-model/src/workspace.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,6 @@ fn cargo_to_crate_graph(
541541

542542
let mut pkg_to_lib_crate = FxHashMap::default();
543543

544-
// Add test cfg for non-sysroot crates
545-
cfg_options.insert_atom("test".into());
546544
cfg_options.insert_atom("debug_assertions".into());
547545

548546
let mut pkg_crates = FxHashMap::default();
@@ -558,6 +556,13 @@ fn cargo_to_crate_graph(
558556
CfgOverrides::Selective(cfg_overrides) => cfg_overrides.get(&cargo[pkg].name),
559557
};
560558

559+
// Add test cfg for local crates
560+
if cargo[pkg].is_local {
561+
replaced_cfg_options = cfg_options.clone();
562+
replaced_cfg_options.insert_atom("test".into());
563+
cfg_options = &replaced_cfg_options;
564+
}
565+
561566
if let Some(overrides) = overrides {
562567
// FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
563568
// in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while

0 commit comments

Comments
 (0)