Skip to content

Under feature unsafe_fields, unsafe union fields are semantically permitted thereby contradicting the RFC #157019

@fmease

Description

@fmease

RFC 3458 states:

The use of unsafe fields on unions shall remain [semantically] forbidden while the impact of this feature on unions is decided.

"impact of this feature on unions" links to Future possibility "Safe Unions", so it doesn't seem "decided".

However, the compiler accepts this code:

#![feature(unsafe_fields)]

union U { unsafe f: () }

That's most likely the case because the reviewer of the initial implementation seemingly requested this behavior in #132915 (comment) (but it's unclear whether they were referring to the syntax or the semantics which might have been the cause of this confusion).

The current behavior is exercised in tests/ui/unsafe-fields/unsafe-fields.rs.

I've grepped through the PR comments of the RFC and of the initial implementation but couldn't find anything that would explain this discrepancy.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions