Skip to content

Commit

Permalink
codegen: Don't generate repr(C) for enums.
Browse files Browse the repository at this point in the history
That's only undefined for enums with fields.

Fixes rust-lang#1224
See also: https://botbot.me/mozilla/rustc/2018-01-19/?msg=95934948&page=2
  • Loading branch information
emilio committed Jan 19, 2018
1 parent 2b81788 commit fbb6d6f
Show file tree
Hide file tree
Showing 45 changed files with 1 addition and 172 deletions.
4 changes: 1 addition & 3 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2442,9 +2442,7 @@ impl CodeGenerator for Enum {
// TODO(emilio): Delegate this to the builders?
if variation.is_rust() {
attrs.push(attributes::repr(repr_name));
}

if variation.is_bitfield() || variation.is_rust() {
} else if variation.is_bitfield() {
attrs.push(attributes::repr("C"));
}

Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/anon_enum.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct Test {
Expand All @@ -12,7 +10,6 @@ pub struct Test {
}
pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Test__bindgen_ty_1 {
T_NONE = 0,
Expand Down Expand Up @@ -41,7 +38,6 @@ fn bindgen_test_layout_Test() {
);
}
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Baz {
Foo = 0,
Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/anon_enum_trait.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct DataType {
Expand All @@ -19,7 +17,6 @@ pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::ge
pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DataType__bindgen_ty_1 {
generic_type = 0,
Expand All @@ -32,7 +29,6 @@ pub struct Foo {
pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo__bindgen_ty_1 {
Bar = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/anon_enum_whitelist.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO;
pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum _bindgen_ty_1 {
NODE_FLAG_FOO = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/anon_union.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
pub struct TErrorResult {
pub mResult: ::std::os::raw::c_int,
Expand All @@ -14,7 +12,6 @@ pub struct TErrorResult {
pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
TErrorResult_UnionState::HasMessage;
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TErrorResult_UnionState {
HasMessage = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/anon_union_1_0.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl<T> __BindgenUnionField<T> {
Expand Down Expand Up @@ -58,7 +56,6 @@ pub struct TErrorResult {
pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
TErrorResult_UnionState::HasMessage;
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TErrorResult_UnionState {
HasMessage = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/bitfield_align_2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage, Align>
Expand Down Expand Up @@ -84,7 +82,6 @@ where
}
}
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MyEnum {
ONE = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/class_with_inner_struct.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Copy, Clone)]
pub struct A {
Expand Down Expand Up @@ -214,7 +212,6 @@ fn bindgen_test_layout_B() {
);
}
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StepSyntax {
Keyword = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/class_with_inner_struct_1_0.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl<T> __BindgenUnionField<T> {
Expand Down Expand Up @@ -272,7 +270,6 @@ impl Clone for B {
}
}
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StepSyntax {
Keyword = 0,
Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/const_enum_unnamed.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR;
pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum _bindgen_ty_1 {
FOO_BAR = 0,
Expand All @@ -20,7 +17,6 @@ pub struct Foo {
}
pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo__bindgen_ty_1 {
FOO_BAR = 10,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/constify-enum.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID =
nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue;
pub const nsCSSPropertyID_eCSSProperty_COUNT: nsCSSPropertyID =
nsCSSPropertyID::eCSSPropertyAlias_aa;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsCSSPropertyID {
eCSSProperty_a = 0,
Expand Down
5 changes: 0 additions & 5 deletions tests/expectations/tests/empty-enum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub type EmptyConstified = ::std::os::raw::c_uint;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EmptyRustified {
__bindgen_cannot_repr_c_on_empty_enum = 0,
Expand All @@ -15,7 +12,6 @@ pub mod EmptyModule {
pub type Type = ::std::os::raw::c_uint;
}
#[repr(i8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EmptyClassRustified {
__bindgen_cannot_repr_c_on_empty_enum = 0,
Expand All @@ -25,7 +21,6 @@ pub mod EmptyClassModule {
pub type Type = ::std::os::raw::c_char;
}
#[repr(i8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ForwardClassRustified {
__bindgen_cannot_repr_c_on_empty_enum = 0,
Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/enum.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo {
Bar = 0,
Qux = 1,
}
#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Neg {
MinusOne = -1,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/enum_alias.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(u8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Bar {
VAL = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/enum_and_vtable_mangling.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_;
pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum _bindgen_ty_1 {
match_ = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/enum_dupe.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const Foo_Dupe: Foo = Foo::Bar;
#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo {
Bar = 1,
Expand Down
8 changes: 0 additions & 8 deletions tests/expectations/tests/enum_explicit_type.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(u8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo {
Bar = 0,
Qux = 1,
}
#[repr(i8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Neg {
MinusOne = -1,
One = 1,
}
#[repr(u16)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Bigger {
Much = 255,
Larger = 256,
}
#[repr(i64)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MuchLong {
MuchLow = -4294967296,
}
#[repr(i64)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MuchLongLong {
I64_MIN = -9223372036854775808,
}
#[repr(u64)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MuchULongLong {
MuchHigh = 4294967296,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/enum_in_template_with_typedef.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct std_fbstring_core {
Expand All @@ -13,7 +11,6 @@ pub type std_fbstring_core_category_type = u8;
pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category =
std_fbstring_core_Category::Foo;
#[repr(u8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum std_fbstring_core_Category {
Foo = 0,
Expand Down
3 changes: 0 additions & 3 deletions tests/expectations/tests/enum_negative.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(i32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo {
Bar = -2,
Expand Down
5 changes: 0 additions & 5 deletions tests/expectations/tests/enum_packed.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(u8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Foo {
Bar = 0,
Qux = 1,
}
#[repr(i8)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Neg {
MinusOne = -1,
One = 1,
}
#[repr(u16)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Bigger {
Much = 255,
Expand Down
Loading

0 comments on commit fbb6d6f

Please sign in to comment.