Skip to content

cargo rm unexpectedly removes patches #12419

Closed
@dtolnay

Description

@dtolnay

Problem

When I run cargo rm dependency, I expect Cargo to remove the crate dependency from the current crate's [dependencies], and other related necessary changes, like removing dependency from the right-hand side of features that previously enabled an optional dependency on "dependency" or one of its features "dependency/…".

Cargo does these things, but it also wipes out my patch.crates-io section from the workspace's manifest. I could not figure out how this seems related in any way to removing a single dependency, so I think this is a bug.

Steps

# Cargo.toml

[workspace]
members = ["serde", "serde_derive"]

[patch.crates-io]
serde = { path = "serde" }
# serde/Cargo.toml

[package]
name = "serde"
version = "1.0.0"

[dependencies]
serde_derive = { path = "../serde_derive" }
# serde_derive/Cargo.toml

[package]
name = "serde_derive"
version = "1.0.0"

+serde/src/lib.rs and serde_derive/src/lib.rs which can be empty files.

In the serde directory, run:

$ cargo check  # sanity check--the manifests are valid

$ cargo rm serde_derive

Expected diff:

diff --git a/serde/Cargo.toml b/serde/Cargo.toml
index 759de5d..10027d7 100644
--- a/serde/Cargo.toml
+++ b/serde/Cargo.toml
@@ -3,6 +3,3 @@
 [package]
 name = "serde"
 version = "1.0.0"
-
-[dependencies]
-serde_derive = { path = "../serde_derive" }

Actual diff produced by Cargo:

diff --git a/Cargo.toml b/Cargo.toml
index 583dd2f..60ffc4f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,3 @@
 
 [workspace]
 members = ["serde", "serde_derive"]
-
-[patch.crates-io]
-serde = { path = "serde" }
diff --git a/serde/Cargo.toml b/serde/Cargo.toml
index 759de5d..10027d7 100644
--- a/serde/Cargo.toml
+++ b/serde/Cargo.toml
@@ -3,6 +3,3 @@
 [package]
 name = "serde"
 version = "1.0.0"
-
-[dependencies]
-serde_derive = { path = "../serde_derive" }

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.73.0-nightly (7ac9416d8 2023-07-24)
release: 1.73.0-nightly
commit-hash: 7ac9416d82cd4fc5e707c9ec3574d22dff6466e5
commit-date: 2023-07-24
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.1.2-DEV (sys:0.4.63+curl-8.1.2 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Ubuntu 22.04 (jammy) [64-bit]

Metadata

Metadata

Assignees

Labels

C-bugCategory: bugCommand-removeE-mediumExperience: MediumS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions