Skip to content

Commit ff9d000

Browse files
committed
Small tests for derive Eq
1 parent 3fc501f commit ff9d000

12 files changed

+44
-44
lines changed

tests/expectations/tests/derive-hash-blacklisting.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

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

6-
#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }
6+
#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }
77

8-
/// This would derive(Hash) if it didn't contain a blacklisted type,
9-
/// causing us to conservatively avoid deriving hash for it.
8+
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
9+
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
1010
#[repr(C)]
1111
#[derive(Debug, Copy)]
1212
pub struct WhitelistedOne {
@@ -30,7 +30,7 @@ impl Clone for WhitelistedOne {
3030
impl Default for WhitelistedOne {
3131
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3232
}
33-
/// This can't derive(Hash) even if it didn't contain a blacklisted type.
33+
/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type.
3434
#[repr(C)]
3535
#[derive(Debug, Copy)]
3636
pub struct WhitelistedTwo {

tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7-
/// A struct containing a struct containing a float that cannot derive hash.
7+
/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
88
#[repr(C)]
9-
#[derive(Debug, Default, Copy)]
9+
#[derive(Debug, Default, Copy, PartialEq)]
1010
pub struct foo {
1111
pub bar: foo__bindgen_ty_1,
1212
}
1313
#[repr(C)]
14-
#[derive(Debug, Default, Copy)]
14+
#[derive(Debug, Default, Copy, PartialEq)]
1515
pub struct foo__bindgen_ty_1 {
1616
pub a: f32,
1717
pub b: f32,

tests/expectations/tests/derive-hash-struct-with-float-array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7-
/// A struct containing an array of floats that cannot derive hash.
7+
/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
88
#[repr(C)]
9-
#[derive(Debug, Default, Copy)]
9+
#[derive(Debug, Default, Copy, PartialEq)]
1010
pub struct foo {
1111
pub bar: [f32; 3usize],
1212
}

tests/expectations/tests/derive-hash-struct-with-pointer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7-
/// Pointers can derive hash/PartialEq
7+
/// Pointers can derive hash/PartialEq/Eq
88
#[repr(C)]
9-
#[derive(Debug, Copy, Hash, PartialEq)]
9+
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
1010
pub struct ConstPtrMutObj {
1111
pub bar: *const ::std::os::raw::c_int,
1212
}
@@ -29,7 +29,7 @@ impl Default for ConstPtrMutObj {
2929
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3030
}
3131
#[repr(C)]
32-
#[derive(Debug, Copy, Hash, PartialEq)]
32+
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
3333
pub struct MutPtrMutObj {
3434
pub bar: *mut ::std::os::raw::c_int,
3535
}
@@ -52,7 +52,7 @@ impl Default for MutPtrMutObj {
5252
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5353
}
5454
#[repr(C)]
55-
#[derive(Debug, Copy, Hash, PartialEq)]
55+
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
5656
pub struct MutPtrConstObj {
5757
pub bar: *const ::std::os::raw::c_int,
5858
}
@@ -75,7 +75,7 @@ impl Default for MutPtrConstObj {
7575
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
7676
}
7777
#[repr(C)]
78-
#[derive(Debug, Copy, Hash, PartialEq)]
78+
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
7979
pub struct ConstPtrConstObj {
8080
pub bar: *const ::std::os::raw::c_int,
8181
}

tests/expectations/tests/derive-hash-template-def-float.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7-
/// Template definition containing a float, which cannot derive hash.
7+
/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
88
#[repr(C)]
9-
#[derive(Debug, Copy, Clone)]
9+
#[derive(Debug, Copy, Clone, PartialEq)]
1010
pub struct foo<T> {
1111
pub data: T,
1212
pub b: f32,

tests/expectations/tests/derive-hash-template-inst-float.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7-
/// Template definition that doesn't contain float can derive hash
7+
/// Template definition that doesn't contain float can derive hash/partialeq/eq
88
#[repr(C)]
9-
#[derive(Debug, Copy, Clone, Hash)]
9+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1010
pub struct foo<T> {
1111
pub data: T,
1212
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
1313
}
1414
impl <T> Default for foo<T> {
1515
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
1616
}
17-
/// Can derive hash when instantiated with int
17+
/// Can derive hash/partialeq/eq when instantiated with int
1818
#[repr(C)]
19-
#[derive(Debug, Copy, Hash)]
19+
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
2020
pub struct IntStr {
2121
pub a: foo<::std::os::raw::c_int>,
2222
}
@@ -38,9 +38,9 @@ impl Clone for IntStr {
3838
impl Default for IntStr {
3939
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
4040
}
41-
/// Cannot derive hash when instantiated with float
41+
/// Cannot derive hash/eq when instantiated with float but can derive partialeq
4242
#[repr(C)]
43-
#[derive(Debug, Copy)]
43+
#[derive(Debug, Copy, PartialEq)]
4444
pub struct FloatStr {
4545
pub a: foo<f32>,
4646
}
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// bindgen-flags: --with-derive-hash --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
22
//
3-
template<class T>
3+
template <class T>
44
struct Blacklisted {
5-
T t;
5+
T t;
66
};
77

8-
/// This would derive(Hash) if it didn't contain a blacklisted type,
9-
/// causing us to conservatively avoid deriving hash for it.
8+
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
9+
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
1010
struct WhitelistedOne {
11-
Blacklisted<int> a;
11+
Blacklisted<int> a;
1212
};
1313

14-
/// This can't derive(Hash) even if it didn't contain a blacklisted type.
14+
/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type.
1515
struct WhitelistedTwo {
16-
Blacklisted<float> b;
16+
Blacklisted<float> b;
1717
};

tests/headers/derive-hash-struct-with-anon-struct-float.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// bindgen-flags: --with-derive-hash
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
22
//
3-
/// A struct containing a struct containing a float that cannot derive hash.
3+
/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
44
struct foo {
55
struct {
66
float a;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// bindgen-flags: --with-derive-hash
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
22
//
3-
/// A struct containing an array of floats that cannot derive hash.
3+
/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
44
struct foo {
55
float bar[3];
66
};

tests/headers/derive-hash-struct-with-pointer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// bindgen-flags: --with-derive-hash --with-derive-partialeq
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
22
//
3-
/// Pointers can derive hash/PartialEq
3+
/// Pointers can derive hash/PartialEq/Eq
44
struct ConstPtrMutObj {
55
int* const bar;
66
};

tests/headers/derive-hash-template-def-float.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// bindgen-flags: --with-derive-hash
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
22
//
3-
/// Template definition containing a float, which cannot derive hash.
4-
template<typename T>
3+
/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
4+
template <typename T>
55
struct foo {
66
T data;
77
float b;
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// bindgen-flags: --with-derive-hash
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
22
//
3-
/// Template definition that doesn't contain float can derive hash
4-
template<typename T>
3+
/// Template definition that doesn't contain float can derive hash/partialeq/eq
4+
template <typename T>
55
struct foo {
66
T data;
77
};
88

9-
/// Can derive hash when instantiated with int
9+
/// Can derive hash/partialeq/eq when instantiated with int
1010
struct IntStr {
1111
foo<int> a;
1212
};
1313

14-
/// Cannot derive hash when instantiated with float
14+
/// Cannot derive hash/eq when instantiated with float but can derive partialeq
1515
struct FloatStr {
1616
foo<float> a;
1717
};

0 commit comments

Comments
 (0)