Skip to content

Commit ada0ac5

Browse files
committed
codegen: Don't automatically derive Debug and Copy for non-rust enums.
Fixes rust-lang#2143
1 parent bcbd72d commit ada0ac5

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/codegen/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,14 +3005,9 @@ impl CodeGenerator for Enum {
30053005

30063006
if !variation.is_const() {
30073007
let mut derives = derives_of_item(item, ctx);
3008-
// For backwards compat, enums always derive Debug/Clone/Eq/PartialEq/Hash, even
3009-
// if we don't generate those by default.
3010-
if !item.annotations().disallow_debug() {
3011-
derives.insert(DerivableTraits::DEBUG);
3012-
}
3013-
if !item.annotations().disallow_copy() {
3014-
derives.insert(DerivableTraits::COPY);
3015-
}
3008+
// For backwards compat, enums always derive
3009+
// Clone/Eq/PartialEq/Hash, even if we don't generate those by
3010+
// default.
30163011
derives.insert(
30173012
DerivableTraits::CLONE |
30183013
DerivableTraits::HASH |

tests/expectations/tests/enum-no-debug-rust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct foo {
1313
pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A;
1414
pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B;
1515
#[repr(u32)]
16-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
16+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
1717
pub enum foo__bindgen_ty_1 {
1818
FOO_A = 0,
1919
FOO_B = 1,
@@ -51,7 +51,7 @@ impl Default for foo {
5151
}
5252
}
5353
#[repr(u32)]
54-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
54+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
5555
pub enum Foo {
5656
Bar = 0,
5757
Qux = 1,
@@ -70,8 +70,8 @@ pub enum NoDebug {
7070
}
7171
#[repr(u32)]
7272
/// <div rustbindgen derive="Debug"></div>
73-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
73+
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
7474
pub enum Debug {
7575
Debug1 = 0,
7676
Debug2 = 1,
77-
}
77+
}

0 commit comments

Comments
 (0)