Problem
cargo add can modify existing entries, like adding more features. When using a standard table (as opposed to an inline table, see #10849), comments get deleted.
Steps
Note: steps are using this is a test case in cargo and these crates don't normally exist
With Cargo.toml:
[workspace]
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
[dependencies.your-face]
version="99999.0.0" # Hello world
features=["eyes"] # Goodbye moon
run
$ cargo add your-face -F features nose
and you'll get
[workspace]
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
[dependencies.your-face]
version = "99999.0.0"
features = ["eyes"]
Possible Solution(s)
There are two problems
- We drop the existing formatting
- We explicitly call
table.fmt() which deletes all decor
The reason for the latter is so the trailing space in inline tables is removed when an item is no longer the last.
Notes
No response
Version
No response