Skip to content

Commit 8657668

Browse files
committed
fix(add): Reduce the chance of breaking the user's formatting
1 parent 983eafb commit 8657668

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/cargo/util/toml_mut/manifest.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ fn fix_feature_activations(
496496
for idx in remove_list.iter().rev() {
497497
feature_values.remove(*idx);
498498
}
499+
if !remove_list.is_empty() {
500+
// HACK: Instead of cleaning up the users formatting from having removed a feature, we just
501+
// re-format the whole feature list
502+
feature_values.fmt();
503+
}
499504

500505
if status == DependencyStatus::Required {
501506
for value in feature_values.iter_mut() {
@@ -516,8 +521,6 @@ fn fix_feature_activations(
516521
}
517522
}
518523
}
519-
520-
feature_values.fmt();
521524
}
522525

523526
pub fn str_or_1_len_table(item: &toml_edit::Item) -> bool {

tests/testsuite/cargo_add/preserve_features_table/out/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ edition = "2021"
99
your-face = { version = "99999.0.0" }
1010

1111
[features]
12-
default = ["a", "b", "c"]
13-
a = ["your-face/nose"]
12+
default = [
13+
"a",
14+
"b",
15+
"c",
16+
]
17+
a = ["your-face/nose", # but not the mouth and nose
18+
]
1419
b = []
1520
c = []

0 commit comments

Comments
 (0)