-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-default_field_values`#![feature(default_field_values)]``#![feature(default_field_values)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
#![feature(default_field_values)]
union U
{
x: i32 = 1,
y: f32 = 2.,
}
I expected to see this happen:
The compiler rejects the program. The default field values RFC does not mention unions, Default
cannot be derived for unions, and there appears to be no way to use these default field values.
Instead, this happened:
The compiler accepts the program.
Meta
rustc --version --verbose
:
1.89.0-nightly
(2025-06-11 e703dff8fe220b78195c)
scottmcm, workingjubilee, sukhmel, Kobzol, estebank and 1 more
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-default_field_values`#![feature(default_field_values)]``#![feature(default_field_values)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
workingjubilee commentedon Jun 16, 2025
I wonder if we can enable deriving Default for unions if a default field value is given and that union variant selected via something like
#[default]
?Nonetheless, it seems far better to simply yeet this unintended consequence and figure that sort of thing out later. ( Notably, this would require that additional
#[default]
extension to begin with. )Rollup merge of rust-lang#142570 - jieyouxu:disunion, r=estebank
Rollup merge of rust-lang#142570 - jieyouxu:disunion, r=estebank
Rollup merge of rust-lang#142570 - jieyouxu:disunion, r=estebank
Unrolled build for #142570
Rollup merge of #142570 - jieyouxu:disunion, r=estebank