Skip to content

Commit

Permalink
fix(fix): Dont remove features when making implicit features explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 5, 2024
1 parent 961e5dd commit 74d2af0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]),
))
});
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,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])
Expand All @@ -2728,10 +2728,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"]
Expand Down

0 comments on commit 74d2af0

Please sign in to comment.