forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small dedicated tests for derive Hash
- Loading branch information
Zhiting Zhu
committed
Aug 9, 2017
1 parent
3edb811
commit b4895d9
Showing
13 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> } | ||
|
||
/// This would derive(Hash) if it didn't contain a blacklisted type, | ||
/// causing us to conservatively avoid deriving hash for it. | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct WhitelistedOne { | ||
pub a: Blacklisted<::std::os::raw::c_int>, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_WhitelistedOne() { | ||
assert_eq!(::std::mem::size_of::<WhitelistedOne>() , 4usize , concat ! ( | ||
"Size of: " , stringify ! ( WhitelistedOne ) )); | ||
assert_eq! (::std::mem::align_of::<WhitelistedOne>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( WhitelistedOne ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const WhitelistedOne ) ) . a as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( WhitelistedOne ) , "::" | ||
, stringify ! ( a ) )); | ||
} | ||
impl Clone for WhitelistedOne { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for WhitelistedOne { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
/// This can't derive(Hash) even if it didn't contain a blacklisted type. | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct WhitelistedTwo { | ||
pub b: Blacklisted<f32>, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_WhitelistedTwo() { | ||
assert_eq!(::std::mem::size_of::<WhitelistedTwo>() , 4usize , concat ! ( | ||
"Size of: " , stringify ! ( WhitelistedTwo ) )); | ||
assert_eq! (::std::mem::align_of::<WhitelistedTwo>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( WhitelistedTwo ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const WhitelistedTwo ) ) . b as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( WhitelistedTwo ) , "::" | ||
, stringify ! ( b ) )); | ||
} | ||
impl Clone for WhitelistedTwo { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for WhitelistedTwo { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
/// A struct containing a struct containing a float that cannot derive hash. | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy)] | ||
pub struct foo { | ||
pub bar: foo__bindgen_ty_1, | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy)] | ||
pub struct foo__bindgen_ty_1 { | ||
pub a: f32, | ||
pub b: f32, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_foo__bindgen_ty_1() { | ||
assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! | ||
( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); | ||
assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat | ||
! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , | ||
"::" , stringify ! ( a ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as | ||
usize } , 4usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , | ||
"::" , stringify ! ( b ) )); | ||
} | ||
impl Clone for foo__bindgen_ty_1 { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
#[test] | ||
fn bindgen_test_layout_foo() { | ||
assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( | ||
"Size of: " , stringify ! ( foo ) )); | ||
assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( foo ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , | ||
0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( foo ) , "::" , | ||
stringify ! ( bar ) )); | ||
} | ||
impl Clone for foo { | ||
fn clone(&self) -> Self { *self } | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/expectations/tests/derive-hash-struct-with-float-array.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
/// A struct containing an array of floats that cannot derive hash. | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy)] | ||
pub struct foo { | ||
pub bar: [f32; 3usize], | ||
} | ||
#[test] | ||
fn bindgen_test_layout_foo() { | ||
assert_eq!(::std::mem::size_of::<foo>() , 12usize , concat ! ( | ||
"Size of: " , stringify ! ( foo ) )); | ||
assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( foo ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , | ||
0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( foo ) , "::" , | ||
stringify ! ( bar ) )); | ||
} | ||
impl Clone for foo { | ||
fn clone(&self) -> Self { *self } | ||
} |
99 changes: 99 additions & 0 deletions
99
tests/expectations/tests/derive-hash-struct-with-pointer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
/// Pointers can derive hash | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Hash)] | ||
pub struct ConstPtrMutObj { | ||
pub bar: *const ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_ConstPtrMutObj() { | ||
assert_eq!(::std::mem::size_of::<ConstPtrMutObj>() , 8usize , concat ! ( | ||
"Size of: " , stringify ! ( ConstPtrMutObj ) )); | ||
assert_eq! (::std::mem::align_of::<ConstPtrMutObj>() , 8usize , concat ! ( | ||
"Alignment of " , stringify ! ( ConstPtrMutObj ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const ConstPtrMutObj ) ) . bar as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( ConstPtrMutObj ) , "::" | ||
, stringify ! ( bar ) )); | ||
} | ||
impl Clone for ConstPtrMutObj { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for ConstPtrMutObj { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Hash)] | ||
pub struct MutPtrMutObj { | ||
pub bar: *mut ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_MutPtrMutObj() { | ||
assert_eq!(::std::mem::size_of::<MutPtrMutObj>() , 8usize , concat ! ( | ||
"Size of: " , stringify ! ( MutPtrMutObj ) )); | ||
assert_eq! (::std::mem::align_of::<MutPtrMutObj>() , 8usize , concat ! ( | ||
"Alignment of " , stringify ! ( MutPtrMutObj ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const MutPtrMutObj ) ) . bar as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( MutPtrMutObj ) , "::" , | ||
stringify ! ( bar ) )); | ||
} | ||
impl Clone for MutPtrMutObj { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for MutPtrMutObj { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Hash)] | ||
pub struct MutPtrConstObj { | ||
pub bar: *const ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_MutPtrConstObj() { | ||
assert_eq!(::std::mem::size_of::<MutPtrConstObj>() , 8usize , concat ! ( | ||
"Size of: " , stringify ! ( MutPtrConstObj ) )); | ||
assert_eq! (::std::mem::align_of::<MutPtrConstObj>() , 8usize , concat ! ( | ||
"Alignment of " , stringify ! ( MutPtrConstObj ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const MutPtrConstObj ) ) . bar as * const _ as | ||
usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( MutPtrConstObj ) , "::" | ||
, stringify ! ( bar ) )); | ||
} | ||
impl Clone for MutPtrConstObj { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for MutPtrConstObj { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Hash)] | ||
pub struct ConstPtrConstObj { | ||
pub bar: *const ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_ConstPtrConstObj() { | ||
assert_eq!(::std::mem::size_of::<ConstPtrConstObj>() , 8usize , concat ! ( | ||
"Size of: " , stringify ! ( ConstPtrConstObj ) )); | ||
assert_eq! (::std::mem::align_of::<ConstPtrConstObj>() , 8usize , concat ! | ||
( "Alignment of " , stringify ! ( ConstPtrConstObj ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const ConstPtrConstObj ) ) . bar as * const _ | ||
as usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( ConstPtrConstObj ) , | ||
"::" , stringify ! ( bar ) )); | ||
} | ||
impl Clone for ConstPtrConstObj { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for ConstPtrConstObj { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/expectations/tests/derive-hash-template-def-float.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
/// Template definition containing a float, which cannot derive hash. | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct foo<T> { | ||
pub data: T, | ||
pub b: f32, | ||
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, | ||
} | ||
impl <T> Default for foo<T> { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} |
84 changes: 84 additions & 0 deletions
84
tests/expectations/tests/derive-hash-template-inst-float.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
/// Template definition that doesn't contain float can derive hash | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Clone, Hash)] | ||
pub struct foo<T> { | ||
pub data: T, | ||
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, | ||
} | ||
impl <T> Default for foo<T> { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
/// Can derive hash when instantiated with int | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Hash)] | ||
pub struct IntStr { | ||
pub a: foo<::std::os::raw::c_int>, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_IntStr() { | ||
assert_eq!(::std::mem::size_of::<IntStr>() , 4usize , concat ! ( | ||
"Size of: " , stringify ! ( IntStr ) )); | ||
assert_eq! (::std::mem::align_of::<IntStr>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( IntStr ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const IntStr ) ) . a as * const _ as usize } , | ||
0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( IntStr ) , "::" , | ||
stringify ! ( a ) )); | ||
} | ||
impl Clone for IntStr { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for IntStr { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
/// Cannot derive hash when instantiated with float | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct FloatStr { | ||
pub a: foo<f32>, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_FloatStr() { | ||
assert_eq!(::std::mem::size_of::<FloatStr>() , 4usize , concat ! ( | ||
"Size of: " , stringify ! ( FloatStr ) )); | ||
assert_eq! (::std::mem::align_of::<FloatStr>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( FloatStr ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const FloatStr ) ) . a as * const _ as usize } | ||
, 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( FloatStr ) , "::" , | ||
stringify ! ( a ) )); | ||
} | ||
impl Clone for FloatStr { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for FloatStr { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
#[test] | ||
fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { | ||
assert_eq!(::std::mem::size_of::<foo<::std::os::raw::c_int>>() , 4usize , | ||
concat ! ( | ||
"Size of template specialization: " , stringify ! ( | ||
foo<::std::os::raw::c_int> ) )); | ||
assert_eq!(::std::mem::align_of::<foo<::std::os::raw::c_int>>() , 4usize , | ||
concat ! ( | ||
"Alignment of template specialization: " , stringify ! ( | ||
foo<::std::os::raw::c_int> ) )); | ||
} | ||
#[test] | ||
fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { | ||
assert_eq!(::std::mem::size_of::<foo<f32>>() , 4usize , concat ! ( | ||
"Size of template specialization: " , stringify ! ( foo<f32> ) | ||
)); | ||
assert_eq!(::std::mem::align_of::<foo<f32>>() , 4usize , concat ! ( | ||
"Alignment of template specialization: " , stringify ! ( | ||
foo<f32> ) )); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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>> }" | ||
// | ||
template<class T> | ||
struct Blacklisted { | ||
T t; | ||
}; | ||
|
||
/// This would derive(Hash) if it didn't contain a blacklisted type, | ||
/// causing us to conservatively avoid deriving hash for it. | ||
struct WhitelistedOne { | ||
Blacklisted<int> a; | ||
}; | ||
|
||
/// This can't derive(Hash) even if it didn't contain a blacklisted type. | ||
struct WhitelistedTwo { | ||
Blacklisted<float> b; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// bindgen-flags: --with-derive-hash | ||
// | ||
/// A struct containing a struct containing a float that cannot derive hash. | ||
struct foo { | ||
struct { | ||
float a; | ||
float b; | ||
} bar; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// bindgen-flags: --with-derive-hash | ||
// | ||
/// A struct containing an array of floats that cannot derive hash. | ||
struct foo { | ||
float bar[3]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// bindgen-flags: --with-derive-hash | ||
// | ||
/// Pointers can derive hash | ||
struct ConstPtrMutObj { | ||
int* const bar; | ||
}; | ||
|
||
struct MutPtrMutObj { | ||
int* bar; | ||
}; | ||
|
||
struct MutPtrConstObj { | ||
const int* bar; | ||
}; | ||
|
||
struct ConstPtrConstObj { | ||
const int* const bar; | ||
}; |
Oops, something went wrong.