- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
Open
Labels
C-bugCategory: bugCategory: bugCommand-addS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Description
Problem
When having a feature called x and running cargo add x --optional the x feature gets overwritten with x = ["dep:x"]
Steps
- Have the following 
Cargo.toml: 
[package]
name = "tmp"
version = "0.1.0"
edition = "2024"
[dependencies]
cookie_store = { version = "0.22", optional = true }
[features]
cookie = ["dep:cookie_store"]- Run 
cargo add cookie --optional - Now the Cargo.toml looks like this, with 
dep:cookie_storenowhere to be seen. 
[package]
name = "tmp"
version = "0.1.0"
edition = "2024"
[dependencies]
cookie = { version = "0.18.1", optional = true }
cookie_store = { version = "0.22", optional = true }
[features]
cookie = ["dep:cookie"]Possible Solution(s)
Theres three solutions I could think of:
- The safe option is to just not generate the feature in this case, so just leave 
cookie = ["dep:cookie_store"]alone. - The other option would be to add it to the feature 
cookie = ["dep:cookie_store", "dep:cookie"]. In this case that's what I would want but I think it's quite dangerous as users would not expect it and in biggerCargo.tomls seeing that change would be hard. - Add it under another name 
_cookie = ["dep:cookie"]? But idk what to do when that name is taken already as well. 
Personally I like option 1 the most.
Notes
No response
Version
cargo 1.92.0-nightly (81c3f77a4 2025-10-10)
release: 1.92.0-nightly
commit-hash: 81c3f77a467359c8be6bc747dc93ec66a6e4ce11
commit-date: 2025-10-10
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Fedora 42.0.0 (Adams) [64-bit]
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bugCommand-addS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.