Open georgmu opened 1 month ago
When cargo add
looks for available features to display and validate against, it looks to the oldest version compatible with your version requirement, assuming
In your case, its picking time = "0.1.0"
and only allowing features from that version.
The issue you're encountering with using cargo add and the version = "" syntax is related to how Cargo resolves features for dependencies. When you specify a version as "", Cargo does not fetch the features for the latest version of the crate, which is why you're seeing the error about the unrecognized feature.
-Check Latest Version: If you want to automatically use the latest version while also ensuring you have the right features, you can check the latest version of the crate and specify that version explicitly: `
cargo search time
-Using cargo update: If you want to ensure that your dependencies are updated to the latest versions, you can run:
cargo update
-Feature List Retrieval: If you want to see what features are available for a crate without adding it, you can use:
cargo search time
` This will show you the latest version and its features. -Using cargo add with Specific Version: If you want to add the crate with a specific version and include features, you can do so directly:
> cargo add time@0.3 -F serde
@Kelvin-1013 please don't post LLM responses without reading and reformatting.
Problem
When trying to run
cargo add crate -F feature
withcrate = "*"
orcrate = { version="*" }
in Cargo.toml, an error is returned.Steps
Add
time = "*"
to Cargo.tomlRun the following command:
Change
time = "*"
totime = "0.3"
Run the command again:
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 (80d82ca22 2024-09-27) release: 1.83.0-nightly commit-hash: 80d82ca22abbee5fb7b51fa1abeb1ae34e99e88a 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]