diff options
13 files changed, 411 insertions, 0 deletions
diff --git a/tests/expectations/struct_with_anon_struct_array_float.rs b/tests/expectations/struct_with_anon_struct_array_float.rs new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/expectations/struct_with_anon_struct_array_float.rs diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs new file mode 100644 index 00000000..c345d1aa --- /dev/null +++ b/tests/expectations/tests/derive-hash-blacklisting.rs @@ -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() } } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs new file mode 100644 index 00000000..051a3636 --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -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 } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs new file mode 100644 index 00000000..bb4a6b5d --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -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 } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs new file mode 100644 index 00000000..007fd2f9 --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -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() } } +} diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs new file mode 100644 index 00000000..e1d7836c --- /dev/null +++ b/tests/expectations/tests/derive-hash-template-def-float.rs @@ -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() } } +} diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs new file mode 100644 index 00000000..dd18053f --- /dev/null +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -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> ) )); +} diff --git a/tests/headers/derive-hash-blacklisting.hpp b/tests/headers/derive-hash-blacklisting.hpp new file mode 100644 index 00000000..ee819c17 --- /dev/null +++ b/tests/headers/derive-hash-blacklisting.hpp @@ -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; +}; diff --git a/tests/headers/derive-hash-struct-with-anon-struct-float.h b/tests/headers/derive-hash-struct-with-anon-struct-float.h new file mode 100644 index 00000000..2b76cd23 --- /dev/null +++ b/tests/headers/derive-hash-struct-with-anon-struct-float.h @@ -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; +}; diff --git a/tests/headers/derive-hash-struct-with-float-array.h b/tests/headers/derive-hash-struct-with-float-array.h new file mode 100644 index 00000000..53f0c79d --- /dev/null +++ b/tests/headers/derive-hash-struct-with-float-array.h @@ -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]; +}; diff --git a/tests/headers/derive-hash-struct-with-pointer.h b/tests/headers/derive-hash-struct-with-pointer.h new file mode 100644 index 00000000..262b6fb4 --- /dev/null +++ b/tests/headers/derive-hash-struct-with-pointer.h @@ -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; +}; diff --git a/tests/headers/derive-hash-template-def-float.hpp b/tests/headers/derive-hash-template-def-float.hpp new file mode 100644 index 00000000..28885ed1 --- /dev/null +++ b/tests/headers/derive-hash-template-def-float.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: --with-derive-hash +// +/// Template definition containing a float, which cannot derive hash. +template<typename T> +struct foo { + T data; + float b; +}; diff --git a/tests/headers/derive-hash-template-inst-float.hpp b/tests/headers/derive-hash-template-inst-float.hpp new file mode 100644 index 00000000..59af69bd --- /dev/null +++ b/tests/headers/derive-hash-template-inst-float.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --with-derive-hash +// +/// Template definition that doesn't contain float can derive hash +template<typename T> +struct foo { + T data; +}; + +/// Can derive hash when instantiated with int +struct IntStr { + foo<int> a; +}; + +/// Cannot derive hash when instantiated with float +struct FloatStr { + foo<float> a; +}; |