fix(fix): Dont remove features when making implicit features explicit

This commit is contained in:
Ed Page 2024-06-05 15:27:00 -05:00
parent fbe1cd1ab7
commit 078383bd0f
2 changed files with 11 additions and 10 deletions

View File

@ -456,18 +456,19 @@ fn add_feature_for_unused_deps(pkg: &Package, parent: &mut dyn toml_edit::TableL
for dep in manifest.dependencies() {
let dep_name_in_toml = dep.name_in_toml();
if dep.is_optional() && !activated_opt_deps.contains(dep_name_in_toml.as_str()) {
fixes += 1;
if let Some(features) = parent
.entry("features")
.or_insert(toml_edit::table())
.as_table_like_mut()
{
features.insert(
dep_name_in_toml.as_str(),
toml_edit::Item::Value(toml_edit::Value::Array(toml_edit::Array::from_iter(
&[format!("dep:{}", dep_name_in_toml)],
))),
);
features
.entry(dep_name_in_toml.as_str())
.or_insert_with(|| {
fixes += 1;
toml_edit::Item::Value(toml_edit::Value::Array(
toml_edit::Array::from_iter(&[format!("dep:{}", dep_name_in_toml)]),
))
});
}
}
}

View File

@ -2705,7 +2705,7 @@ unrelated-dep-feature = ["unrelated-feature/a", "unrelated-feature/b"]
.with_stderr(
"\
[MIGRATING] Cargo.toml from 2021 edition to 2024
[FIXED] Cargo.toml (3 fixes)
[FIXED] Cargo.toml (1 fix)
[UPDATING] `dummy-registry` index
[LOCKING] 5 packages to latest compatible versions
[CHECKING] foo v0.1.0 ([CWD])
@ -2730,10 +2730,10 @@ renamed-feature = { version = "0.1.0", optional = true }
unrelated-feature = { version = "0.1.0", optional = true }
[features]
dep-feature = ["dep:dep-feature"]
dep-feature = ["dep-feature/a", "dep-feature/b"]
dep-and-dep-feature = ["dep:dep-and-dep-feature", "dep-and-dep-feature/a", "dep-and-dep-feature/b"]
renamed = ["renamed-feature/a", "renamed-feature/b"]
unrelated-feature = ["dep:unrelated-feature"]
unrelated-feature = []
unrelated-dep-feature = ["unrelated-feature/a", "unrelated-feature/b"]
renamed-feature = ["dep:renamed-feature"]