Skip to content

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

@not-my-profile

Description

@not-my-profile

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-featuresArea: features — conditional compilationS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions