Skip to content

cargo add deletes comments in TOML unexpectedly under certain conditions #13645

Closed
@cyqsimon

Description

@cyqsimon

Problem

Running cargo add <EXISTING_DEP> causes the preceding comments to be deleted in Cargo.toml.

Steps

  1. Create a new project with cargo new
  2. Add the following to Cargo.toml:
[dependencies]
# Duis aliqua ullamco incididunt cupidatat Lorem est consequat nostrud mollit veniam fugiat.
# Magna elit anim officia reprehenderit tempor exercitation in do voluptate cillum sunt deserunt duis est.
chrono = "0.4.35"
# Enim dolor veniam ipsum pariatur ullamco laborum veniam cillum dolore aliqua in officia.
# Proident esse cillum mollit adipisicing culpa ad labore labore.
serde = "1.0.197"
# Tempor sunt duis labore dolore consequat labore ad.
# Ipsum eu do amet excepteur sint nisi officia ullamco occaecat eu commodo amet veniam.
  1. Run cargo add chrono/serde (in practise the likely reason you do this is to specify additional features, but that's not necessary for a MRE)
  2. Observe that the two lines of preceding comments are deleted

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.77.0 (3fe68eabf 2024-02-29)
release: 1.77.0
commit-hash: 3fe68eabf93cbf3772bbcad09a9206c783e2de3f
commit-date: 2024-02-29
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: EndeavourOS Rolling Release (rolling) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions