Skip to content

Compiler should reject union field definitions having default values #142555

Closed
@zopsicle

Description

@zopsicle

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-default_field_values`#![feature(default_field_values)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions