Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Confusing error when adding optional dependency to [features] #10125

Open
not-my-profile opened this issue Nov 26, 2021 · 1 comment
Open

Confusing error when adding optional dependency to [features] #10125

not-my-profile opened this issue Nov 26, 2021 · 1 comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-features Area: features — conditional compilation S-triage Status: This issue is waiting on initial triage.

Comments

@not-my-profile
Copy link

Anybody who does not know that optional dependencies implicitly define a feature of the same name might end up with a Cargo.toml file like the following:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1", optional = true }

[features]
tokio = ["tokio"]

For this entirely reasonable human error Cargo however yields a completely confusing error message:

error: failed to parse manifest at `/tmp/foo/Cargo.toml`

Caused by:
  optional dependency `tokio` is not included in any feature
  Make sure that `dep:tokio` is included in one of features in the [features] table.

Reproduced with:

% cargo --version         
cargo 1.56.0 (4ed5d137b 2021-10-04)
% cargo +nightly --version
cargo 1.58.0-nightly (ad50d0d26 2021-11-17)
@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-features Area: features — conditional compilation labels Dec 6, 2021
@Eh2406
Copy link
Contributor

Eh2406 commented Dec 10, 2021

In the long run namespaced-features will hopefully make this mess less common.
In the short run I would love to see error messages improve, although I have no idea how difficult that would be in this case.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-features Area: features — conditional compilation S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

4 participants