Skip to content

Univariant enums cannot have repr set #10292

Closed
@sp3d

Description

@sp3d

In writing bindings for C libraries which feature enums in their API, single-variant enums can and do occur. However, binding these by generating a matching Rust enum with only one variant is not currently possible, as rustc gives
error: unsupported representation for univariant enum
on code like

#[repr(C)]
enum Foo
{
    Bar,
    //Dummy,
}

Currently this can be worked-around by adding a dummy variant as shown, but that shouldn't be necessary as it requires handling in consumer code, e.g. matches.

CC @jld who added the very very useful ability to use #[repr(C)] in the first place. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions