Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cyqsimon opened this issue Mar 26, 2024 · 2 comments · Fixed by #13655
Closed

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

cyqsimon opened this issue Mar 26, 2024 · 2 comments · Fixed by #13655
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@cyqsimon
Copy link
Contributor

cyqsimon commented Mar 26, 2024

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]
@cyqsimon cyqsimon added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 26, 2024
@epage
Copy link
Contributor

epage commented Mar 26, 2024

Can you try this on nightly? i believe this was fixed in #13402

@cyqsimon
Copy link
Contributor Author

cyqsimon commented Mar 26, 2024

Nope. Unless cargo +nightly add isn't actually using nightly which I doubt is the case.

$ cargo +nightly -Vv
cargo 1.79.0-nightly (d438c80c4 2024-03-19)
release: 1.79.0-nightly
commit-hash: d438c80c45c24be676ef5867edc79d0a14910efe
commit-date: 2024-03-19
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: EndeavourOS Rolling Release (rolling) [64-bit]
$ cargo +nightly add serde
# Same behaviour

epage added a commit to epage/cargo that referenced this issue Mar 26, 2024
A case the tests showed but isn't covered here is when a `[features]`
table is created, the dependencies-end comment gets attached to that,
e.g. see cargo_add/overwrite_optional

Fixes rust-lang#13645
bors added a commit that referenced this issue Mar 27, 2024
fix(add): Preserve comments when updating simple deps

### What does this PR try to resolve?

Fixes #13645

### How should we test and review this PR?

A case the tests showed but isn't covered here is when a `[features]`
table is created, the dependencies-end comment gets attached to that,
e.g. see cargo_add/overwrite_optional

### Additional information
@bors bors closed this as completed in e476bd5 Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants