Skip to content

Commit fbb6d6f

Browse files
committed
codegen: Don't generate repr(C) for enums.
That's only undefined for enums with fields. Fixes #1224 See also: https://botbot.me/mozilla/rustc/2018-01-19/?msg=95934948&page=2
1 parent 2b81788 commit fbb6d6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1
-172
lines changed

src/codegen/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2442,9 +2442,7 @@ impl CodeGenerator for Enum {
24422442
// TODO(emilio): Delegate this to the builders?
24432443
if variation.is_rust() {
24442444
attrs.push(attributes::repr(repr_name));
2445-
}
2446-
2447-
if variation.is_bitfield() || variation.is_rust() {
2445+
} else if variation.is_bitfield() {
24482446
attrs.push(attributes::repr("C"));
24492447
}
24502448

tests/expectations/tests/anon_enum.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
#[derive(Debug, Default, Copy, Clone, PartialEq)]
97
pub struct Test {
@@ -12,7 +10,6 @@ pub struct Test {
1210
}
1311
pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE;
1412
#[repr(u32)]
15-
#[repr(C)]
1613
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1714
pub enum Test__bindgen_ty_1 {
1815
T_NONE = 0,
@@ -41,7 +38,6 @@ fn bindgen_test_layout_Test() {
4138
);
4239
}
4340
#[repr(u32)]
44-
#[repr(C)]
4541
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
4642
pub enum Baz {
4743
Foo = 0,

tests/expectations/tests/anon_enum_trait.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
97
pub struct DataType {
@@ -19,7 +17,6 @@ pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::ge
1917
pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
2018
pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
2119
#[repr(i32)]
22-
#[repr(C)]
2320
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2421
pub enum DataType__bindgen_ty_1 {
2522
generic_type = 0,
@@ -32,7 +29,6 @@ pub struct Foo {
3229
pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
3330
pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
3431
#[repr(u32)]
35-
#[repr(C)]
3632
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3733
pub enum Foo__bindgen_ty_1 {
3834
Bar = 0,

tests/expectations/tests/anon_enum_whitelist.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO;
86
pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR;
97
#[repr(u32)]
10-
#[repr(C)]
118
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
129
pub enum _bindgen_ty_1 {
1310
NODE_FLAG_FOO = 0,

tests/expectations/tests/anon_union.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
pub struct TErrorResult {
97
pub mResult: ::std::os::raw::c_int,
@@ -14,7 +12,6 @@ pub struct TErrorResult {
1412
pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
1513
TErrorResult_UnionState::HasMessage;
1614
#[repr(i32)]
17-
#[repr(C)]
1815
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1916
pub enum TErrorResult_UnionState {
2017
HasMessage = 0,

tests/expectations/tests/anon_union_1_0.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
97
impl<T> __BindgenUnionField<T> {
@@ -58,7 +56,6 @@ pub struct TErrorResult {
5856
pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
5957
TErrorResult_UnionState::HasMessage;
6058
#[repr(i32)]
61-
#[repr(C)]
6259
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
6360
pub enum TErrorResult_UnionState {
6461
HasMessage = 0,

tests/expectations/tests/bitfield_align_2.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
97
pub struct __BindgenBitfieldUnit<Storage, Align>
@@ -84,7 +82,6 @@ where
8482
}
8583
}
8684
#[repr(u32)]
87-
#[repr(C)]
8885
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8986
pub enum MyEnum {
9087
ONE = 0,

tests/expectations/tests/class_with_inner_struct.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
#[derive(Copy, Clone)]
97
pub struct A {
@@ -214,7 +212,6 @@ fn bindgen_test_layout_B() {
214212
);
215213
}
216214
#[repr(i32)]
217-
#[repr(C)]
218215
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
219216
pub enum StepSyntax {
220217
Keyword = 0,

tests/expectations/tests/class_with_inner_struct_1_0.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
97
impl<T> __BindgenUnionField<T> {
@@ -272,7 +270,6 @@ impl Clone for B {
272270
}
273271
}
274272
#[repr(i32)]
275-
#[repr(C)]
276273
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
277274
pub enum StepSyntax {
278275
Keyword = 0,

tests/expectations/tests/const_enum_unnamed.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR;
86
pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ;
97
#[repr(u32)]
10-
#[repr(C)]
118
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
129
pub enum _bindgen_ty_1 {
1310
FOO_BAR = 0,
@@ -20,7 +17,6 @@ pub struct Foo {
2017
}
2118
pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR;
2219
#[repr(u32)]
23-
#[repr(C)]
2420
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2521
pub enum Foo__bindgen_ty_1 {
2622
FOO_BAR = 10,

tests/expectations/tests/constify-enum.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID =
86
nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue;
97
pub const nsCSSPropertyID_eCSSProperty_COUNT: nsCSSPropertyID =
108
nsCSSPropertyID::eCSSPropertyAlias_aa;
119
#[repr(u32)]
12-
#[repr(C)]
1310
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1411
pub enum nsCSSPropertyID {
1512
eCSSProperty_a = 0,

tests/expectations/tests/empty-enum.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub type EmptyConstified = ::std::os::raw::c_uint;
86
#[repr(u32)]
9-
#[repr(C)]
107
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
118
pub enum EmptyRustified {
129
__bindgen_cannot_repr_c_on_empty_enum = 0,
@@ -15,7 +12,6 @@ pub mod EmptyModule {
1512
pub type Type = ::std::os::raw::c_uint;
1613
}
1714
#[repr(i8)]
18-
#[repr(C)]
1915
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2016
pub enum EmptyClassRustified {
2117
__bindgen_cannot_repr_c_on_empty_enum = 0,
@@ -25,7 +21,6 @@ pub mod EmptyClassModule {
2521
pub type Type = ::std::os::raw::c_char;
2622
}
2723
#[repr(i8)]
28-
#[repr(C)]
2924
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3025
pub enum ForwardClassRustified {
3126
__bindgen_cannot_repr_c_on_empty_enum = 0,

tests/expectations/tests/enum.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(u32)]
8-
#[repr(C)]
96
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107
pub enum Foo {
118
Bar = 0,
129
Qux = 1,
1310
}
1411
#[repr(i32)]
15-
#[repr(C)]
1612
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1713
pub enum Neg {
1814
MinusOne = -1,

tests/expectations/tests/enum_alias.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(u8)]
8-
#[repr(C)]
96
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107
pub enum Bar {
118
VAL = 0,

tests/expectations/tests/enum_and_vtable_mangling.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_;
86
pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
97
#[repr(u32)]
10-
#[repr(C)]
118
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
129
pub enum _bindgen_ty_1 {
1310
match_ = 0,

tests/expectations/tests/enum_dupe.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
pub const Foo_Dupe: Foo = Foo::Bar;
86
#[repr(u32)]
9-
#[repr(C)]
107
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
118
pub enum Foo {
129
Bar = 1,

tests/expectations/tests/enum_explicit_type.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(u8)]
8-
#[repr(C)]
96
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107
pub enum Foo {
118
Bar = 0,
129
Qux = 1,
1310
}
1411
#[repr(i8)]
15-
#[repr(C)]
1612
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1713
pub enum Neg {
1814
MinusOne = -1,
1915
One = 1,
2016
}
2117
#[repr(u16)]
22-
#[repr(C)]
2318
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2419
pub enum Bigger {
2520
Much = 255,
2621
Larger = 256,
2722
}
2823
#[repr(i64)]
29-
#[repr(C)]
3024
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3125
pub enum MuchLong {
3226
MuchLow = -4294967296,
3327
}
3428
#[repr(i64)]
35-
#[repr(C)]
3629
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3730
pub enum MuchLongLong {
3831
I64_MIN = -9223372036854775808,
3932
}
4033
#[repr(u64)]
41-
#[repr(C)]
4234
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
4335
pub enum MuchULongLong {
4436
MuchHigh = 4294967296,

tests/expectations/tests/enum_in_template_with_typedef.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(C)]
86
#[derive(Debug, Default, Copy, Clone)]
97
pub struct std_fbstring_core {
@@ -13,7 +11,6 @@ pub type std_fbstring_core_category_type = u8;
1311
pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category =
1412
std_fbstring_core_Category::Foo;
1513
#[repr(u8)]
16-
#[repr(C)]
1714
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1815
pub enum std_fbstring_core_Category {
1916
Foo = 0,

tests/expectations/tests/enum_negative.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(i32)]
8-
#[repr(C)]
96
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107
pub enum Foo {
118
Bar = -2,

tests/expectations/tests/enum_packed.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
/* automatically generated by rust-bindgen */
22

3-
43
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
54

6-
75
#[repr(u8)]
8-
#[repr(C)]
96
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107
pub enum Foo {
118
Bar = 0,
129
Qux = 1,
1310
}
1411
#[repr(i8)]
15-
#[repr(C)]
1612
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1713
pub enum Neg {
1814
MinusOne = -1,
1915
One = 1,
2016
}
2117
#[repr(u16)]
22-
#[repr(C)]
2318
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2419
pub enum Bigger {
2520
Much = 255,

0 commit comments

Comments
 (0)