Skip to content

Confusing behavior when passing features to package #11415

@kamirr

Description

@kamirr

Problem

If you have a package foo in your workspace, and it is not the default build target (cargo build builds bar), you build it via cargo build -p foo. Now, if you want to enable a feature, the intuitive approach would be to cargo build -p foo --features new-feat. This will cause an error if bar doesn't have such feature, but it will build just fine if bar also has the new-feat feautre.

This is immensly confusing, as the feature is enabled for a package which one isn't even attempting to build. The solution is to, of course, invoke cargo build -p foo --features "foo/new-feat", but finding out about this is not trivial.

Proposed Solution

Emit a warning when running cargo build -p MEMBER --features FEATURE if both MEMBER and the root package have this feature declared.

Notes

If this is deemed useful, I can tackle the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions