Skip to content

Commit 9dcddf6

Browse files
committed
Remove feature components that activate features of dev-dependencies
For example, syn has a feature `test` that activates the `all-features` feature of the dev-dependency `syn-test-suite`: ```toml [features] test = ["syn-test-suite/all-features"] [dev-dependencies.syn-test-suite] version = "0" ``` We don't store the dev-dependencies in the index which causes Cargo to complain when fetching `syn` because the feature refers to a dependency that doesn't exist.
1 parent 7e9c0a4 commit 9dcddf6

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ lint_groups_priority = { level = "allow", priority = 1 } # Remove after 1.80. ht
2929

3030
[workspace.dependencies]
3131
argh = { version = "0.1.12", default-features = false }
32-
registry-conformance = { version = "0.5.0", registry = "registry-conformance" }
32+
registry-conformance = { version = "0.5.2", registry = "registry-conformance" }
3333
snafu = { version = "0.8.2", default-features = false, features = ["rust_1_65", "std"] }
3434
tokio = { version = "1.37.0", default-features = false, features = ["macros", "process", "rt-multi-thread"] }
3535

src/main.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,33 @@ enum ExtractRootCargoTomlError {
10141014
fn adapt_cargo_toml_to_index_entry(
10151015
global: &Global,
10161016
config: &ConfigV1,
1017-
cargo_toml: cargo_toml::Root,
1017+
mut cargo_toml: cargo_toml::Root,
10181018
checksum_hex: String,
10191019
) -> index_entry::Root {
1020+
// Remove features that refer to dev-dependencies as we don't
1021+
// track those anyway.
1022+
{
1023+
// Ignore dependencies that also occur as a regular or build
1024+
// dependency, as we *do* track those.
1025+
let reg_dep_names = cargo_toml.dependencies.keys();
1026+
let build_dep_names = cargo_toml.build_dependencies.keys();
1027+
let mut only_dev_dep_names = cargo_toml.dev_dependencies.keys().collect::<BTreeSet<_>>();
1028+
for name in reg_dep_names.chain(build_dep_names) {
1029+
only_dev_dep_names.remove(name);
1030+
}
1031+
1032+
for name in only_dev_dep_names {
1033+
// We don't care about the official package name here as the
1034+
// feature syntax has to match the user-specified dependency
1035+
// name.
1036+
let prefix = format!("{name}/");
1037+
1038+
for enabled in cargo_toml.features.values_mut() {
1039+
enabled.retain(|enable| !enable.starts_with(&prefix));
1040+
}
1041+
}
1042+
}
1043+
10201044
let mut deps: Vec<_> = cargo_toml
10211045
.dependencies
10221046
.into_iter()
@@ -1126,6 +1150,9 @@ mod cargo_toml {
11261150
#[serde(default)]
11271151
pub build_dependencies: Dependencies,
11281152

1153+
#[serde(default)]
1154+
pub dev_dependencies: Dependencies,
1155+
11291156
#[serde(default)]
11301157
pub target: BTreeMap<String, Target>,
11311158
}

0 commit comments

Comments
 (0)