Skip to content

cargo add disables previously enabled features when converting between _ and - #10680

@Aloso

Description

@Aloso

Problem

cargo add can be used to add an optional feature to an existing dependency:

> cargo add once_cell -F unstable
    Updating crates.io index
      Adding once_cell v1.11.0 to dependencies.
             Features:
             + alloc
             + race
             + std
             + unstable
             - atomic-polyfill
             - parking_lot
             - parking_lot_core

> cargo add once_cell -F parking_lot
    Updating crates.io index
      Adding once_cell v1.11.0 to dependencies.
             Features:
             + alloc
             + parking_lot
             + parking_lot_core
             + race
             + std
             + unstable
             - atomic-polyfill
# note that `unstable` is still enabled from before!

Furthermore, cargo add can convert _ to - and vice versa in crate names. However, when doing this translation, existing features are dropped:

> cargo add once-cell -F parking_lot
    Updating crates.io index
warning: translating `once-cell` to `once_cell`
      Adding once_cell v1.11.0 to dependencies.
             Features:
             + alloc
             + parking_lot
             + parking_lot_core
             + race
             + std
             - atomic-polyfill
             - unstable
# note that `unstable` is no longer enabled!

cargo add should behave the same whether the crate name was written in its canonical form or not.

Version

cargo 1.63.0-nightly (a4c1cd0eb 2022-05-18)
release: 1.63.0-nightly
commit-hash: a4c1cd0eb6b18082a7e693f5a665548fe1534be4
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1n)
os: Manjaro 21.2.6 (Qonos) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-addS-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