-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Comments
When
In your case, its picking |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The behavior is written down here in code: cargo/src/cargo/ops/cargo_add/mod.rs Lines 1040 to 1054 in d8cb5fb
It seems pretty like an implementation detail relying on the assumption in the comment. I don't think this should be documented, and picking up the latest version isn't better either. I would propose we close this as the behavior is intended. |
Thank you for your detailed report on the issue with cargo add and the version="*" specification. I appreciate the clarity in your steps and the examples provided. It's clear that the current behavior is tied to how Cargo determines the lowest common denominator for features based on the earliest compatible version. Your observation about it defaulting to time = "0.1.0" and the limitations that come with that is insightful. While I understand the rationale behind this implementation, I agree that it can lead to confusion, especially when users expect the latest features to be available with a wildcard version. However, since this behavior seems intentional and documented in the code, I support closing this issue as 'not planned.' It might be worth considering whether we could improve the documentation around this behavior in the future to help users understand the implications of using wildcard versions better. Thanks again for bringing this to our attention! |
imo if we did anything, it would likely to be lint against wildcard dependencies, see #5340 |
It seems odd that cargo, which has a ton of code about resolving versions of crates, doesn't reuse this for determining which version's features are in play here? Especially in this case where the actual version is already known in Cargo.lock? A diagnostic sounds good to me -- the current behaviour is surprising. |
The current version is in
|
Problem
When trying to run
cargo add crate -F feature
withcrate = "*"
orcrate = { version="*" }
in Cargo.toml, an error is returned.Steps
time = "*"
to Cargo.tomltime = "*"
totime = "0.3"
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]
The text was updated successfully, but these errors were encountered: