Skip to content

Commit 530694c

Browse files
committed
Add a test for simple blacklisting + derive(Hash)
We already have a test for more complicated template instantiations and blacklisting and their affects on deriving `Hash`, but it is good to have sanity tests for the simple cases too.
1 parent 2433965 commit 530694c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
pub struct BlacklistMe(u8);
7+
8+
/// Because this type contains a blacklisted type, it should not derive Hash.
9+
#[repr(C)]
10+
pub struct ShouldNotDeriveHash {
11+
pub a: BlacklistMe,
12+
}
13+
#[test]
14+
fn bindgen_test_layout_ShouldNotDeriveHash() {
15+
assert_eq!(::std::mem::size_of::<ShouldNotDeriveHash>() , 1usize , concat
16+
! ( "Size of: " , stringify ! ( ShouldNotDeriveHash ) ));
17+
assert_eq! (::std::mem::align_of::<ShouldNotDeriveHash>() , 1usize ,
18+
concat ! (
19+
"Alignment of " , stringify ! ( ShouldNotDeriveHash ) ));
20+
assert_eq! (unsafe {
21+
& ( * ( 0 as * const ShouldNotDeriveHash ) ) . a as * const _
22+
as usize } , 0usize , concat ! (
23+
"Alignment of field: " , stringify ! ( ShouldNotDeriveHash ) ,
24+
"::" , stringify ! ( a ) ));
25+
}
26+
impl Default for ShouldNotDeriveHash {
27+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// bindgen-flags: --with-derive-hash --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);'
2+
3+
struct BlacklistMe {};
4+
5+
/**
6+
* Because this type contains a blacklisted type, it should not derive Hash.
7+
*/
8+
struct ShouldNotDeriveHash {
9+
BlacklistMe a;
10+
};

0 commit comments

Comments
 (0)