Skip to content

There should be a way to make a type as "stably a 1-ZST" for repr(transparent) purposes #155925

@RalfJung

Description

@RalfJung

Currently, if one crate defines a 1-ZST with private fields, and then another crate tries to use that in a repr(transparent) type, that produces an error:

// Crate A
pub struct MyMarkerType((());
// Crate B

#[repr(transparent)]
struct Transparent(i32, A::MyMarkerType);

This warning is caused by #78586. The intention of the warning is to guard against a semver hazard: if crate A adds non-zero-sized fields to MyMarkerType in the future, that would break compilation of crate B.

However, what if crate A actually wants to promise that it will never add such fields? Currently it has no way to express this, the lint will always fire for types with private fields in other crates. This is on track to becoming a hard error (#78586).

See here for where @CAD97 originally brought up this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    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