Skip to content

Do not consider uninhabited 1-ZST "trivial" for the purpose of repr(transparent)? #147588

@RalfJung

Description

@RalfJung

Currently, repr(transparent) ignores all 1-ZST, including uninhabited types. Together with the ABI promise we are making for repr(transparent), that means we cannot in any way exploit the uninhabitedness of a type for the purpose of the function call ABI -- which has led to #135802; we had to actually pessimize the ABI for functions returning things like (i32, !) to account for this. (Cc @zachs18)

@rust-lang/lang is that a deliberate feature of repr(transparent)? It seems more like an accident to me.

However, it is an accident that is non-trivial to fix, since it turns out hyper contains a type like this:

#[repr(transparent)]
struct Neutered<B> {
    _inner: B,
    impossible: Impossible,
}

enum Impossible {}

Under a more reasonable set of rules for repr(transparent) that does not just ignore uninhabited 1-ZST, this type would be rejected. @seanmonstar @nox is there any particular reason why this type is repr(transparent)? It is still uninhabited, making it insta-UB to create an element, even by transmutation from B.

A crater run has been queued in #147589.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions