Skip to content

Transition out weak feature syntax in an edition #10556

@ehuss

Description

@ehuss
Contributor

Problem

The difference between package/feature and package?/feature syntax is unfortunate as it can be a little confusing and inelegant. Ideally we would have kept the original syntax, but the ? was added to retain backwards compatibility.

Proposed Solution

It might be worth considering dropping the ? syntax in the next edition. package/feature would behave the same as the ? variant. With the use of toml_edit, it may be possible to enhance cargo fix in order to automatically update Cargo.toml to retain backwards compatibility. If the package is optional, then it would rewrite the [features] table to convert "package/feature" to "dep:package", "package/feature" (and also possibly define a feature named "package" if it doesn't already exist and dep:package isn't already used).

Notes

No response

Activity

added
A-featuresArea: features — conditional compilation
C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
on Apr 12, 2022
added
A-edition-nextArea: may require a breaking change over an edition
on Feb 7, 2023
moved this from Ideas to Accepted in Cargo Edition 2024 Planningon Sep 5, 2023
moved this from Accepted to Ideas in Cargo Edition 2024 Planningon Sep 18, 2023
epage

epage commented on Mar 22, 2024

@epage
Contributor

There was a recent zulip thread on this.

One idea brought up is to start by deprecating dep/feature syntax, likely gated by an MSRV check. One of the challenges with this is in collecting user feedback. A deprecation is a two-way door that we can leverage to raise awareness of the change to help decide if this is a direction we'd want to commit to. If we get little actionable negative feedback or if the feedback is generally positive, those could be good signals for deciding to change the dep/feature syntax meaning on a new edition.

added
T-infraTeam: infrastructure
S-needs-team-inputStatus: Needs input from team on whether/how to proceed.
on Apr 10, 2024
epage

epage commented on Jun 4, 2024

@epage
Contributor

I believe the issue hints at it but its easy to overlook. A subtle difference between "dep_name/feature_name" and "dep:dep_name", "dep_name?/feature_name" is that dep: is required to suppress the creation of the implicit feature.

This came up in #14010

kornelski

kornelski commented on Apr 18, 2025

@kornelski
Contributor

I've written (bad) parsers for this syntax twice, and I still find the syntax tricky to reason about.

To me the odd thing is that the dep: prefix, ?, and /feature are not orthogonal. If I have dep:foo, then I can't change it to dep:foo/feature to enable it with a feature. I can't write dep:foo?/feature either. The logic of "features can't have features, therefore the non-dep part must be a dep" is harder to reason for me. I'd prefer "dep:foo" is always a dep, without dep: it's always a feature, and if features can't have features enabled, that syntax should be an error.

So I'm supportive of transitioning it out, and suggest that allowing dep: prefix wherever referring to a dependency could be a first step towards making this syntax more regular and orthogonal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-nextArea: may require a breaking change over an editionA-featuresArea: features — conditional compilationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-team-inputStatus: Needs input from team on whether/how to proceed.T-infraTeam: infrastructure

    Type

    No type

    Projects

    Status

    Ideas

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@epage@kornelski

        Issue actions

          Transition out weak feature syntax in an edition · Issue #10556 · rust-lang/cargo