-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Tracking Issue for Unnamed Enum Variants (Open Enums) #156628
Copy link
Copy link
Open
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-unnamed_enum_variants`#![feature(unnamed_enum_variants)]``#![feature(unnamed_enum_variants)]`I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.S-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-unnamed_enum_variants`#![feature(unnamed_enum_variants)]``#![feature(unnamed_enum_variants)]`I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.S-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is the tracking issue for RFC 3894 - "Open up your enum with an unnamed variant". It was informally approved as a lang experiment in the 2026-04-22 design meeting, and has an associated 2026 project goal. @joshtriplett is the lang-team champion for the experiment.
The feature gate for the issue is
#![feature(unnamed_enum_variants)].CC @rust-lang/lang, @rust-lang/lang-advisors
Motivation for the experiment
While
reprallows for a stable ABI for a field-lessenum, there's no good way for an enum to declare itself as future-compatible with discriminants that may be assigned to variants in the future. The most notable case for this is FFI with a C enum.bindgenavoids generatingrepr(C)enumto interoperate with a Cenumby default because Cenums are "open" - it is valid to cast an integer that isn't associated with a named value to an enum type. By contrast, Rustenums are "closed": the user always declares every valid value. There is no invalid bit pattern for a Cenumbut for a Rustenum, anything undeclared is invalid.Its current solutions to soundly interoperate with a C
enumare less ergonomic to use than if we could use a Rustenumsoundly.Proposed Solution
This lang experiment proposes to allow unnamed variants to claim discriminants as valid for an
enumahead-of-time. The below is an open enum and may be cast fromu8:This uses the Rust closed-enum syntax to declare all valid discriminants up-front, and thus functions as an open enum with the backing integer. This benefits projects that work with many open enums, such as Rust for Linux.
Further background and motivation is provided in the RFC and project goal. The goal of this lang experiment is to determine:
ascasting from integer be a separate feature?)About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
repr(Int)enumwith singular discriminantsrepr(Int)enumrepr(C)enumascast fromIntfor open enumscore(mem::discriminant,derive(Debug)) to support unnamed variantsrustfmtUnresolved Questions
repr(Int)enumto be ABI compatible withInt?Implementation history
Coming soon to a PR near you!