diff --git a/src/cargo/util/toml_mut/manifest.rs b/src/cargo/util/toml_mut/manifest.rs index 4e354eeb5..5529b8029 100644 --- a/src/cargo/util/toml_mut/manifest.rs +++ b/src/cargo/util/toml_mut/manifest.rs @@ -516,7 +516,9 @@ fn fix_feature_activations( } = parsed_value { if dep_name == dep_key && weak { - *value = format!("{dep_name}/{dep_feature}").into(); + let mut new_value = toml_edit::Value::from(format!("{dep_name}/{dep_feature}")); + *new_value.decor_mut() = value.decor().clone(); + *value = new_value; } } } diff --git a/tests/testsuite/cargo_add/preserve_features_table/out/Cargo.toml b/tests/testsuite/cargo_add/preserve_features_table/out/Cargo.toml index 2ed73f97c..39acd1016 100644 --- a/tests/testsuite/cargo_add/preserve_features_table/out/Cargo.toml +++ b/tests/testsuite/cargo_add/preserve_features_table/out/Cargo.toml @@ -14,7 +14,8 @@ default = [ "b", "c", ] -a = ["your-face/nose", # but not the mouth and nose +a = [ + "your-face/nose", # but not the mouth and nose ] b = [] c = []