rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.76k stars 2.42k forks source link

cannot add `{}` as a dependency to itself #14570

Closed loynoir closed 1 month ago

loynoir commented 1 month ago

Problem

Previously, I use self dev dependency to activate testing only features.

But, now self dev dependency seems not working

$ cargo add -p XXX --dev XXX -F test_counter -F dependency_mock
      Adding XXX (local) to dev-dependencies
error: cannot add `XXX` as a dependency to itself

https://github.com/rust-lang/cargo/blob/eaee77dc1584be45949b75e4c4c9a841605e3a4b/src/cargo/ops/cargo_add/mod.rs#L125

Any equivalent in new cargo?

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.83.0-nightly (c1fa840a8 2024-08-29)

zachs18 commented 1 month ago

You can still add the relevant dev-dependency manually to Cargo.toml, e.g.

[dev-dependencies]
XXX = { path = ".", features = ["foo"] }

Any equivalent in new cargo?

I don't know think cargo's version of cargo add ever worked for this use-case; the line you quoted was added when cargo add became part of cargo. cargo add was added in Rust 1.62.0, and this doesn't work using that version either. I'm not sure if this worked in cargo-edit's version of cargo add prior to it being added to cargo itself.

loynoir commented 1 month ago

I use channel = "nightly-2024-08-28" yesterday.

Around one week ago, line did add to Cargo.toml.

xxx = { workspace = true, features = ["testing_counter"] }

Update toolchain to channel = "nightly-2024-09-15" yesterday.

No idea what happen.