Skip to content

Comments aren't preserved when modifying an existing stanrdard toml table with cargo add #10850

@epage

Description

@epage

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions