rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.85k stars 2.43k forks source link

Incorrect documentation for default-features in workspace dependencies #14841

Open konstin opened 1 week ago

konstin commented 1 week ago

The cargo docs on workspace packages say (https://doc.rust-lang.org/nightly/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace):

Along with the workspace key, dependencies can also include these keys:

  • optional: Note that the[workspace.dependencies] table is not allowed to specify optional.
  • features: These are additive with the features declared in the [workspace.dependencies]

Other than optional and features, inherited dependencies cannot use any other dependency key (such as version or default-features).

Trying this out however, cargo does not seem to mind the default-features key:

[workspace]
members = ["workspace-member"]
resolver = "2"

[workspace.dependencies]
flate2 = { version = "1.0.35", default-features = false }
url = { version = "2.5.3", features = ["serde"] }
[package]
name = "workspace-member"
version = "0.1.0"
edition = "2021"

[dependencies]
flate2 = { workspace = true, default-features = true }
url = { workspace = true, default-features = false }

It's unfortunately not clear to me from the docs if default-features are inherited.

weihanglo commented 1 week ago

Documenting is hard ;( This is something we've tried to make it clear. See https://doc.rust-lang.org/nightly/edition-guide/rust-2024/cargo-inherited-default-features.html and https://github.com/rust-lang/cargo/issues/12162#issuecomment-2020763765.

Any idea how to add a succinct explanation to the doc? cc @Muscraft

konstin commented 1 week ago

Something like "A workspace member will inherit default-features = false if set in the workspace root, but it can't deactivate default features if they weren't deactivated by the workspace root". I found the table in https://github.com/rust-lang/cargo/issues/12162#issuecomment-2020763765 very helpful.