Skip to content

Commit

Permalink
gen: Derive Eq, PartialEq and Hash for enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Apr 30, 2016
1 parent 759f506 commit 9f78ea9
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,9 +1491,9 @@ fn cenum_to_rs(ctx: &mut GenCtx,
}));

attrs.push(if ctx.options.derive_debug {
mk_deriving_attr(ctx, &["Debug", "Copy", "Clone"])
mk_deriving_attr(ctx, &["Debug", "Copy", "Clone", "Eq", "PartialEq", "Hash"])
} else {
mk_deriving_attr(ctx, &["Copy", "Clone"])
mk_deriving_attr(ctx, &["Copy", "Clone", "Eq", "PartialEq", "Hash"])
});

items.push(P(ast::Item {
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/class_with_inner_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn bindgen_test_layout_Struct_B() {
assert_eq!(::std::mem::align_of::<Struct_B>() , 4usize);
}
#[repr(i32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_StepSyntax {
Keyword = 0,
FunctionalWithoutKeyword = 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo { Bar = 0, Qux = 1, }
#[repr(i32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Neg { MinusOne = -1, One = 1, }
2 changes: 1 addition & 1 deletion tests/expectations/enum_and_vtable_mangling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_enum_and_vtable_mangling_hpp_unnamed_1 {
match_ = 0,
whatever_else = 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/enum_dupe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

pub const Dupe: Enum_Foo = Enum_Foo::Bar;
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo { Bar = 1, }
10 changes: 5 additions & 5 deletions tests/expectations/enum_explicit_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@


#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo { Bar = 0, Qux = 1, }
#[repr(i8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Neg { MinusOne = -1, One = 1, }
#[repr(u16)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Bigger { Much = 255, Larger = 256, }
#[repr(i64)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_MuchLong { MuchLow = -4294967296, }
#[repr(u64)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_MuchLongLong { MuchHigh = 4294967296, }
2 changes: 1 addition & 1 deletion tests/expectations/enum_negative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@


#[repr(i32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo { Bar = -2, Qux = 1, }
6 changes: 3 additions & 3 deletions tests/expectations/enum_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo { Bar = 0, Qux = 1, }
#[repr(i8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Neg { MinusOne = -1, One = 1, }
#[repr(u16)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Bigger { Much = 255, Larger = 256, }
2 changes: 1 addition & 1 deletion tests/expectations/func_ptr_in_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


#[repr(i32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_baz { _BindgenOpaqueEnum = 0, }
#[repr(C)]
#[derive(Debug, Copy)]
Expand Down
8 changes: 4 additions & 4 deletions tests/expectations/jsval_layout_opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
}
pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47;
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum JSValueType {
JSVAL_TYPE_DOUBLE = 0,
JSVAL_TYPE_INT32 = 1,
Expand All @@ -40,7 +40,7 @@ pub enum JSValueType {
JSVAL_TYPE_MISSING = 33,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum JSValueTag {
JSVAL_TAG_MAX_DOUBLE = 131056,
JSVAL_TAG_INT32 = 131057,
Expand All @@ -53,7 +53,7 @@ pub enum JSValueTag {
JSVAL_TAG_OBJECT = 131064,
}
#[repr(u64)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum JSValueShiftedTag {
JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663,
JSVAL_SHIFTED_TAG_INT32 = 18444633011384221696,
Expand All @@ -66,7 +66,7 @@ pub enum JSValueShiftedTag {
JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum JSWhyMagic {
JS_ELEMENTS_HOLE = 0,
JS_NO_ITER_VALUE = 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/overflowed_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@


#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Foo {
BAP_ARM = 9698489,
BAP_X86 = 11960045,
BAP_X86_64 = 3128633167,
}
#[repr(u16)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_Bar { One = 1, Big = 2, }
2 changes: 1 addition & 1 deletion tests/expectations/weird_bitfields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


#[repr(u32)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Enum_nsStyleSVGOpacitySource {
eStyleSVGOpacitySource_Normal = 0,
eStyleSVGOpacitySource_ContextFillOpacity = 1,
Expand Down

0 comments on commit 9f78ea9

Please sign in to comment.