New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Univariant enums cannot have repr set #10292

Closed
sp3d opened this Issue Nov 5, 2013 · 5 comments

Comments

Projects
None yet
5 participants
@sp3d
Copy link
Contributor

sp3d commented Nov 5, 2013

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. :)

@cmr

This comment has been minimized.

Copy link
Member

cmr commented Feb 18, 2014

The bug is that univariant enums are allowed no representation whatsoever, they seem to be forced to 1-byte. (Updating issue title to reflect this)

@cmr cmr added I-wrong labels Feb 18, 2014

@cmr

This comment has been minimized.

Copy link
Member

cmr commented Feb 18, 2014

ping @jld

@cmr

This comment has been minimized.

Copy link
Member

cmr commented Feb 18, 2014

Nominating, seems important for FFI. Is backwards compatible, though.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Feb 27, 2014

Assigning P-high, not a 1.0 issue.

@pnkfelix pnkfelix added P-high and removed I-nominated labels Feb 27, 2014

@simnalamburt

This comment has been minimized.

Copy link
Contributor

simnalamburt commented Feb 13, 2015

CC Me

@arielb1 arielb1 added A-ffi and removed I-wrong labels Jun 29, 2015

stepancheg added a commit to stepancheg/rust that referenced this issue Jan 27, 2016

Allow #[repr(i32)] for univariant enum
```
#[repr(i32)]
enum Univariant {
    X = 17
}
```

Fixes rust-lang#10292

stepancheg added a commit to stepancheg/rust that referenced this issue Jan 27, 2016

Allow #[repr(i32)] for univariant enum
```
#[repr(i32)]
enum Univariant {
    X = 17
}
```

Fixes rust-lang#10292

stepancheg added a commit to stepancheg/rust that referenced this issue Jan 27, 2016

Allow #[repr(i32)] for univariant enum
```
#[repr(i32)]
enum Univariant {
    X = 17
}
```

Fixes rust-lang#10292

bors added a commit that referenced this issue Feb 1, 2016

Auto merge of #31232 - stepancheg:enum-univariant, r=nrc
```
enum Univariant {
    X = 17
}
```

Fixes #10292

@bors bors closed this in #31232 Feb 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment