Skip to content

workspaces.dependencies causes ignore of default-features = false in crate #11329

Closed
@leighmcculloch

Description

@leighmcculloch

Problem

When specifying a workspace dependency it is not obvious, and rather surprising that, not specifying default-features = false in the workspace dependency, means that any default-features = false is ignored in any member crate.

This I assume is because the features of workspace dependencies are additive, and by not specifying default-features = false, the default features are automatically and always enabled.

Steps

  1. Create a workspace with a workspace dependency that has default features.
  2. Add a crate that also specifies the dependency, inherits it from the workspace, and specifies default-features = false.

Possible Solution(s)

There are I think a couple solutions to this problem:

Possible Solution 1: Change the Default in workspace dependencies

This is probably not possible now that the feature is released, but it seems reasonable that workspace depenencies by default should not contribute any features unless explicitly specified. This would mean default-features = false by default in the workspace dependency.

Position Solution 2: Display a warning if a member crate has default-features = false when workspace doesn't

If a workspace doesn't specify default-features = false, but a member crate does, this seems like an error, since the member crate will never achieve the effect of default-features = false. A warning would go a long way to help educate and catch this mistake. The warning for this would be similar to how cargo warns if you include patch entries that aren't getting used.

Notes

No response

Version

cargo 1.64.0 (387270bc7 2022-09-16)
release: 1.64.0
commit-hash: 387270bc7f446d17869c7f208207c73231d6a252
commit-date: 2022-09-16
host: aarch64-apple-darwin
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.84.0 (sys:0.4.55+curl-7.83.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.0.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions