Skip to content

Commit 797b6ba

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 797b6ba

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,31 @@ 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 mut only_dev_dep_names = cargo_toml.dev_dependencies.keys().collect::<BTreeSet<_>>();
1026+
for name in cargo_toml.dependencies.keys().chain(cargo_toml.build_dependencies.keys()) {
1027+
only_dev_dep_names.remove(name);
1028+
}
1029+
1030+
for name in only_dev_dep_names {
1031+
// We don't care about the official package name here as the
1032+
// feature syntax has to match the user-specified dependency
1033+
// name.
1034+
let prefix = format!("{name}/");
1035+
1036+
for enabled in cargo_toml.features.values_mut() {
1037+
enabled.retain(|enable| !enable.starts_with(&prefix));
1038+
}
1039+
}
1040+
}
1041+
10201042
let mut deps: Vec<_> = cargo_toml
10211043
.dependencies
10221044
.into_iter()
@@ -1126,6 +1148,9 @@ mod cargo_toml {
11261148
#[serde(default)]
11271149
pub build_dependencies: Dependencies,
11281150

1151+
#[serde(default)]
1152+
pub dev_dependencies: Dependencies,
1153+
11291154
#[serde(default)]
11301155
pub target: BTreeMap<String, Target>,
11311156
}

0 commit comments

Comments
 (0)