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 cannot enable features if version="*" in Cargo.toml #14648

Open
georgmu opened this issue Oct 6, 2024 · 3 comments
Open

cargo add cannot enable features if version="*" in Cargo.toml #14648

georgmu opened this issue Oct 6, 2024 · 3 comments
Labels
C-bug Category: bug Command-add S-triage Status: This issue is waiting on initial triage.

Comments

@georgmu
Copy link

georgmu commented Oct 6, 2024

Problem

When trying to run cargo add crate -F feature with crate = "*" or crate = { version="*" } in Cargo.toml, an error is returned.

Steps

  1. Add time = "*" to Cargo.toml
  2. Run the following command:
$ cargo +nightly add time -F serde
    Updating crates.io index
      Adding time * to dependencies
error: unrecognized feature for crate time: serde
no features available for crate time
  1. Change time = "*" to time = "0.3"
  2. Run the command again:
$ cargo +nightly add time -F serde
    Updating crates.io index
      Adding time v0.3 to dependencies
             Features as of v0.3.0:
             + alloc
             + serde
             + std
             - formatting
             - itoa
             - large-dates
             - local-offset
             - macros
             - parsing
             - quickcheck
             - quickcheck-dep
             - rand
             - serde-human-readable
             - time-macros

List of features changes when using the last concrete version (0.3.36).

Possible Solution(s)

For version="*", I would expect that it uses the feature list of the used root dependency (as in Cargo.lock) or of the latest version available.

Notes

No response

Version

cargo 1.83.0-nightly (80d82ca 2024-09-27)
release: 1.83.0-nightly
commit-hash: 80d82ca
commit-date: 2024-09-27
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Fedora 41.0.0 (FortyOne) [64-bit]

@georgmu georgmu added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Oct 6, 2024
@epage
Copy link
Contributor

epage commented Oct 7, 2024

When cargo add looks for available features to display and validate against, it looks to the oldest version compatible with your version requirement, assuming

  1. You set the minimum supported version in your version requirement
  2. The dependency doesn't remove features, making this the lowest common denominator for your version requirement. Granted, this gets fuzzy with multi-major version requirements.

In your case, its picking time = "0.1.0" and only allowing features from that version.

@Kelvin-1013

This comment has been minimized.

@weihanglo

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-add S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

4 participants