diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ac28244c54..7d6f8d17e6 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1642,16 +1642,21 @@ impl CodeGenerator for CompInfo { ctx.options().derive_copy { derives.push("Copy"); - if used_template_params.is_some() { - // FIXME: This requires extra logic if you have a big array in a - // templated struct. The reason for this is that the magic: - // fn clone(&self) -> Self { *self } - // doesn't work for templates. - // - // It's not hard to fix though. + + if ctx.options().rust_features().builtin_clone_impls() { derives.push("Clone"); } else { - needs_clone_impl = true; + if used_template_params.is_some() { + // FIXME: This requires extra logic if you have a big array in a + // templated struct. The reason for this is that the magic: + // fn clone(&self) -> Self { *self } + // doesn't work for templates. + // + // It's not hard to fix though. + derives.push("Clone"); + } else { + needs_clone_impl = true; + } } } diff --git a/src/features.rs b/src/features.rs index b89185fd9b..0954d87b84 100644 --- a/src/features.rs +++ b/src/features.rs @@ -90,6 +90,8 @@ macro_rules! rust_target_base { => Stable_1_0 => 1.0; /// Rust stable 1.19 => Stable_1_19 => 1.19; + /// Rust stable 1.21 + => Stable_1_21 => 1.21; /// Nightly rust => Nightly => nightly; ); @@ -100,7 +102,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_19; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { @@ -142,6 +144,8 @@ rust_feature_def!( => const_fn; /// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) => thiscall_abi; + /// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690)) + => builtin_clone_impls; ); impl From for RustFeatures { @@ -152,6 +156,10 @@ impl From for RustFeatures { features.untagged_union = true; } + if rust_target >= RustTarget::Stable_1_21 { + features.builtin_clone_impls = true; + } + if rust_target >= RustTarget::Nightly { features.const_fn = true; features.thiscall_abi = true; @@ -183,6 +191,7 @@ mod test { fn str_to_target() { test_target("1.0", RustTarget::Stable_1_0); test_target("1.19", RustTarget::Stable_1_19); + test_target("1.21", RustTarget::Stable_1_21); test_target("nightly", RustTarget::Nightly); } } diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 8610365697..57bc753da3 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -5,193 +5,265 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_ipv4_tuple { pub src_addr: u32, pub dst_addr: u32, pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, pub sctp_tag: u32, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() - , 4usize , concat ! ( - "Size of: " , stringify ! ( - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() - , 2usize , concat ! ( - "Alignment of " , stringify ! ( - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( - * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) - ) . dport as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , - stringify ! ( dport ) )); - assert_eq! (unsafe { - & ( - * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) - ) . sport as * const _ as usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , - stringify ! ( sport ) )); -} -impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!( + "Alignment of ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize + }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize + }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize - , concat ! ( - "Size of: " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , - 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) . - sctp_tag as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv4_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag - ) )); -} -impl Clone for rte_ipv4_tuple__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { - assert_eq!(::std::mem::size_of::() , 12usize , concat ! ( - "Size of: " , stringify ! ( rte_ipv4_tuple ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ipv4_tuple ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::" - , stringify ! ( src_addr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const - _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::" - , stringify ! ( dst_addr ) )); -} -impl Clone for rte_ipv4_tuple { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv4_tuple)).src_addr as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv4_tuple)).dst_addr as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Default for rte_ipv4_tuple { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_ipv6_tuple { pub src_addr: [u8; 16usize], pub dst_addr: [u8; 16usize], pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, pub sctp_tag: u32, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() - , 4usize , concat ! ( - "Size of: " , stringify ! ( - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() - , 2usize , concat ! ( - "Alignment of " , stringify ! ( - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( - * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) - ) . dport as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , - stringify ! ( dport ) )); - assert_eq! (unsafe { - & ( - * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) - ) . sport as * const _ as usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , - stringify ! ( sport ) )); -} -impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!( + "Alignment of ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize + }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize + }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize - , concat ! ( - "Size of: " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , - 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) . - sctp_tag as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - rte_ipv6_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag - ) )); -} -impl Clone for rte_ipv6_tuple__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { - assert_eq!(::std::mem::size_of::() , 36usize , concat ! ( - "Size of: " , stringify ! ( rte_ipv6_tuple ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ipv6_tuple ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::" - , stringify ! ( src_addr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const - _ as usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::" - , stringify ! ( dst_addr ) )); -} -impl Clone for rte_ipv6_tuple { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv6_tuple)).src_addr as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ipv6_tuple)).dst_addr as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Default for rte_ipv6_tuple { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, @@ -199,22 +271,34 @@ pub union rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { - assert_eq!(::std::mem::size_of::() , 48usize , concat ! ( - "Size of: " , stringify ! ( rte_thash_tuple ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_thash_tuple ) , - "::" , stringify ! ( v4 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_thash_tuple ) , - "::" , stringify ! ( v6 ) )); -} -impl Clone for rte_thash_tuple { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(rte_thash_tuple)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_thash_tuple)).v4 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v4) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_thash_tuple)).v6 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v6) + ) + ); } impl Default for rte_thash_tuple { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index df1732c4c1..ac2fb74719 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct SomeAccessors { pub mNoAccessor: ::std::os::raw::c_int, ///
@@ -17,33 +17,56 @@ pub struct SomeAccessors { } #[test] fn bindgen_test_layout_SomeAccessors() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( SomeAccessors ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( SomeAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const SomeAccessors ) ) . mNoAccessor as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" - , stringify ! ( mNoAccessor ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const SomeAccessors ) ) . mBothAccessors as * - const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" - , stringify ! ( mBothAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const SomeAccessors ) ) . mUnsafeAccessors as * - const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" - , stringify ! ( mUnsafeAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const SomeAccessors ) ) . mImmutableAccessor as - * const _ as usize } , 12usize , concat ! ( - "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" - , stringify ! ( mImmutableAccessor ) )); -} -impl Clone for SomeAccessors { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(SomeAccessors)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(SomeAccessors)) + ); + assert_eq!( + unsafe { &(*(0 as *const SomeAccessors)).mNoAccessor as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mNoAccessor) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const SomeAccessors)).mBothAccessors as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const SomeAccessors)).mUnsafeAccessors as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const SomeAccessors)).mImmutableAccessor as *const _ as usize }, + 12usize, + concat!( + "Alignment of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); } impl SomeAccessors { #[inline] @@ -59,8 +82,7 @@ impl SomeAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut(&mut self) - -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -70,30 +92,43 @@ impl SomeAccessors { } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct AllAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_AllAccessors() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( AllAccessors ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( AllAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AllAccessors ) ) . mBothAccessors as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( AllAccessors ) , "::" , - stringify ! ( mBothAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AllAccessors ) ) . mAlsoBothAccessors as - * const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( AllAccessors ) , "::" , - stringify ! ( mAlsoBothAccessors ) )); -} -impl Clone for AllAccessors { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AllAccessors)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllAccessors)) + ); + assert_eq!( + unsafe { &(*(0 as *const AllAccessors)).mBothAccessors as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(AllAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const AllAccessors)).mAlsoBothAccessors as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(AllAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); } impl AllAccessors { #[inline] @@ -109,38 +144,49 @@ impl AllAccessors { &self.mAlsoBothAccessors } #[inline] - pub fn get_mAlsoBothAccessors_mut(&mut self) - -> &mut ::std::os::raw::c_int { + pub fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mAlsoBothAccessors } } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct AllUnsafeAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_AllUnsafeAccessors() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( AllUnsafeAccessors ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat - ! ( "Alignment of " , stringify ! ( AllUnsafeAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AllUnsafeAccessors ) ) . mBothAccessors - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) , - "::" , stringify ! ( mBothAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AllUnsafeAccessors ) ) . - mAlsoBothAccessors as * const _ as usize } , 4usize , concat ! - ( - "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) , - "::" , stringify ! ( mAlsoBothAccessors ) )); -} -impl Clone for AllUnsafeAccessors { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AllUnsafeAccessors)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllUnsafeAccessors)) + ); + assert_eq!( + unsafe { &(*(0 as *const AllUnsafeAccessors)).mBothAccessors as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const AllUnsafeAccessors)).mAlsoBothAccessors as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); } impl AllUnsafeAccessors { #[inline] @@ -148,8 +194,7 @@ impl AllUnsafeAccessors { &self.mBothAccessors } #[inline] - pub unsafe fn get_mBothAccessors_mut(&mut self) - -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mBothAccessors } #[inline] @@ -157,14 +202,13 @@ impl AllUnsafeAccessors { &self.mAlsoBothAccessors } #[inline] - pub unsafe fn get_mAlsoBothAccessors_mut(&mut self) - -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mAlsoBothAccessors } } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct ContradictAccessors { pub mBothAccessors: ::std::os::raw::c_int, ///
@@ -176,35 +220,56 @@ pub struct ContradictAccessors { } #[test] fn bindgen_test_layout_ContradictAccessors() { - assert_eq!(::std::mem::size_of::() , 16usize , concat - ! ( "Size of: " , stringify ! ( ContradictAccessors ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( ContradictAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictAccessors ) ) . mBothAccessors - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ContradictAccessors ) , - "::" , stringify ! ( mBothAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictAccessors ) ) . mNoAccessors as - * const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( ContradictAccessors ) , - "::" , stringify ! ( mNoAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictAccessors ) ) . - mUnsafeAccessors as * const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( ContradictAccessors ) , - "::" , stringify ! ( mUnsafeAccessors ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictAccessors ) ) . - mImmutableAccessor as * const _ as usize } , 12usize , concat - ! ( - "Alignment of field: " , stringify ! ( ContradictAccessors ) , - "::" , stringify ! ( mImmutableAccessor ) )); -} -impl Clone for ContradictAccessors { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ContradictAccessors)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContradictAccessors)) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictAccessors)).mBothAccessors as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictAccessors)).mNoAccessors as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mNoAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictAccessors)).mUnsafeAccessors as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictAccessors)).mImmutableAccessor as *const _ as usize }, + 12usize, + concat!( + "Alignment of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); } impl ContradictAccessors { #[inline] @@ -220,8 +285,7 @@ impl ContradictAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut(&mut self) - -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -231,28 +295,38 @@ impl ContradictAccessors { } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Replaced { pub mAccessor: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Replaced() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Replaced ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Replaced ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Replaced ) ) . mAccessor as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Replaced ) , "::" , - stringify ! ( mAccessor ) )); -} -impl Clone for Replaced { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Replaced)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Replaced)) + ); + assert_eq!( + unsafe { &(*(0 as *const Replaced)).mAccessor as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Replaced), + "::", + stringify!(mAccessor) + ) + ); } impl Replaced { #[inline] - pub fn get_mAccessor(&self) -> &::std::os::raw::c_int { &self.mAccessor } + pub fn get_mAccessor(&self) -> &::std::os::raw::c_int { + &self.mAccessor + } #[inline] pub fn get_mAccessor_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mAccessor @@ -260,28 +334,38 @@ impl Replaced { } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Wrapper { pub mReplaced: Replaced, } #[test] fn bindgen_test_layout_Wrapper() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Wrapper ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Wrapper ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Wrapper ) ) . mReplaced as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Wrapper ) , "::" , - stringify ! ( mReplaced ) )); -} -impl Clone for Wrapper { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Wrapper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Wrapper)) + ); + assert_eq!( + unsafe { &(*(0 as *const Wrapper)).mReplaced as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Wrapper), + "::", + stringify!(mReplaced) + ) + ); } impl Wrapper { #[inline] - pub fn get_mReplaced(&self) -> &Replaced { &self.mReplaced } + pub fn get_mReplaced(&self) -> &Replaced { + &self.mReplaced + } #[inline] pub fn get_mReplaced_mut(&mut self) -> &mut Replaced { &mut self.mReplaced diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 0cd443a7db..7f68d115cb 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -7,7 +7,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct D { pub _bindgen_opaque_blob: u32, } @@ -24,13 +24,8 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); } -impl Clone for D { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct NotAnnotated { pub f: ::std::os::raw::c_int, } @@ -57,8 +52,3 @@ fn bindgen_test_layout_NotAnnotated() { ) ); } -impl Clone for NotAnnotated { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index b1004274f8..3dfd5ad34f 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct Test { pub foo: ::std::os::raw::c_int, pub bar: f32, @@ -13,27 +13,45 @@ pub struct Test { pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Test__bindgen_ty_1 { T_NONE = 0, } +pub enum Test__bindgen_ty_1 { + T_NONE = 0, +} #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Test ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Test ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . foo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . bar as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( bar ) )); -} -impl Clone for Test { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test)) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).foo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).bar as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(bar) + ) + ); } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Baz { Foo = 0, Bar = 1, } +pub enum Baz { + Foo = 0, + Bar = 1, +} diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index f0c1d364f5..9f5a6c56f1 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -13,21 +13,18 @@ pub type DataType_value_type<_Tp> = _Tp; pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>; -pub const DataType_generic_type: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_depth: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_channels: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_fmt: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_type_: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; +pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum DataType__bindgen_ty_1 { generic_type = 0, } +pub enum DataType__bindgen_ty_1 { + generic_type = 0, +} #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub _address: u8, } @@ -35,14 +32,19 @@ pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Foo__bindgen_ty_1 { Bar = 0, } +pub enum Foo__bindgen_ty_1 { + Bar = 0, +} #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 783a62cf02..4a5054f609 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -5,70 +5,92 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct s { pub u: s__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union s__bindgen_ty_1 { pub field: s__bindgen_ty_1_inner, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct s__bindgen_ty_1_inner { pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { - assert_eq!(::std::mem::size_of::() , 4usize , - concat ! ( "Size of: " , stringify ! ( s__bindgen_ty_1_inner ) - )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( s__bindgen_ty_1_inner ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const s__bindgen_ty_1_inner ) ) . b as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( s__bindgen_ty_1_inner ) - , "::" , stringify ! ( b ) )); -} -impl Clone for s__bindgen_ty_1_inner { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) + ); + assert_eq!( + unsafe { &(*(0 as *const s__bindgen_ty_1_inner)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( s__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( s__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const s__bindgen_ty_1 ) ) . field as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( s__bindgen_ty_1 ) , - "::" , stringify ! ( field ) )); -} -impl Clone for s__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const s__bindgen_ty_1)).field as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field) + ) + ); } impl Default for s__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_s() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( s ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( s ) )); - assert_eq! (unsafe { & ( * ( 0 as * const s ) ) . u as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( s ) , "::" , stringify - ! ( u ) )); -} -impl Clone for s { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s)) + ); + assert_eq!( + unsafe { &(*(0 as *const s)).u as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(s), "::", stringify!(u)) + ); } impl Default for s { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/base-to-derived.rs b/tests/expectations/tests/base-to-derived.rs index 0a9e1c3535..9df54d982e 100644 --- a/tests/expectations/tests/base-to-derived.rs +++ b/tests/expectations/tests/base-to-derived.rs @@ -5,17 +5,20 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct false_type { pub _address: u8, } #[test] fn bindgen_test_layout_false_type() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( false_type ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( false_type ) )); -} -impl Clone for false_type { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(false_type)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(false_type)) + ); } diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index c90513717a..dfd5384775 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct MuchBitfield { pub _bitfield_1: [u8; 5usize], } @@ -22,11 +22,6 @@ fn bindgen_test_layout_MuchBitfield() { concat!("Alignment of ", stringify!(MuchBitfield)) ); } -impl Clone for MuchBitfield { - fn clone(&self) -> Self { - *self - } -} impl MuchBitfield { #[inline] pub fn m0(&self) -> ::std::os::raw::c_char { diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index ebb3fef43e..84362d1232 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -9,28 +9,30 @@ pub const Foo_Baz: Foo = Foo(4); pub const Foo_Duplicated: Foo = Foo(4); pub const Foo_Negative: Foo = Foo(-3); impl ::std::ops::BitOr for Foo { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitor(self, other: Self) -> Self { Foo(self.0 | other.0) } + fn bitor(self, other: Self) -> Self { + Foo(self.0 | other.0) + } } impl ::std::ops::BitOrAssign for Foo { #[inline] - fn bitor_assign(&mut self, rhs: Foo) { self.0 |= rhs.0; } + fn bitor_assign(&mut self, rhs: Foo) { + self.0 |= rhs.0; + } } impl ::std::ops::BitAnd for Foo { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitand(self, other: Self) -> Self { Foo(self.0 & other.0) } + fn bitand(self, other: Self) -> Self { + Foo(self.0 & other.0) + } } impl ::std::ops::BitAndAssign for Foo { #[inline] - fn bitand_assign(&mut self, rhs: Foo) { self.0 &= rhs.0; } + fn bitand_assign(&mut self, rhs: Foo) { + self.0 &= rhs.0; + } } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -40,28 +42,30 @@ pub const Buz_Baz: Buz = Buz(4); pub const Buz_Duplicated: Buz = Buz(4); pub const Buz_Negative: Buz = Buz(-3); impl ::std::ops::BitOr for Buz { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitor(self, other: Self) -> Self { Buz(self.0 | other.0) } + fn bitor(self, other: Self) -> Self { + Buz(self.0 | other.0) + } } impl ::std::ops::BitOrAssign for Buz { #[inline] - fn bitor_assign(&mut self, rhs: Buz) { self.0 |= rhs.0; } + fn bitor_assign(&mut self, rhs: Buz) { + self.0 |= rhs.0; + } } impl ::std::ops::BitAnd for Buz { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitand(self, other: Self) -> Self { Buz(self.0 & other.0) } + fn bitand(self, other: Self) -> Self { + Buz(self.0 & other.0) + } } impl ::std::ops::BitAndAssign for Buz { #[inline] - fn bitand_assign(&mut self, rhs: Buz) { self.0 &= rhs.0; } + fn bitand_assign(&mut self, rhs: Buz) { + self.0 &= rhs.0; + } } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -69,44 +73,43 @@ pub struct Buz(pub ::std::os::raw::c_schar); pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2); impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitor(self, other: Self) -> Self { _bindgen_ty_1(self.0 | other.0) } + fn bitor(self, other: Self) -> Self { + _bindgen_ty_1(self.0 | other.0) + } } impl ::std::ops::BitOrAssign for _bindgen_ty_1 { #[inline] - fn bitor_assign(&mut self, rhs: _bindgen_ty_1) { self.0 |= rhs.0; } + fn bitor_assign(&mut self, rhs: _bindgen_ty_1) { + self.0 |= rhs.0; + } } impl ::std::ops::BitAnd<_bindgen_ty_1> for _bindgen_ty_1 { - type - Output - = - Self; + type Output = Self; #[inline] - fn bitand(self, other: Self) -> Self { _bindgen_ty_1(self.0 & other.0) } + fn bitand(self, other: Self) -> Self { + _bindgen_ty_1(self.0 & other.0) + } } impl ::std::ops::BitAndAssign for _bindgen_ty_1 { #[inline] - fn bitand_assign(&mut self, rhs: _bindgen_ty_1) { self.0 &= rhs.0; } + fn bitand_assign(&mut self, rhs: _bindgen_ty_1) { + self.0 &= rhs.0; + } } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint); #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Dummy { pub _address: u8, } pub const Dummy_DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1); pub const Dummy_DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2); impl ::std::ops::BitOr for Dummy__bindgen_ty_1 { - type - Output - = - Self; + type Output = Self; #[inline] fn bitor(self, other: Self) -> Self { Dummy__bindgen_ty_1(self.0 | other.0) @@ -114,13 +117,12 @@ impl ::std::ops::BitOr for Dummy__bindgen_ty_1 { } impl ::std::ops::BitOrAssign for Dummy__bindgen_ty_1 { #[inline] - fn bitor_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 |= rhs.0; } + fn bitor_assign(&mut self, rhs: Dummy__bindgen_ty_1) { + self.0 |= rhs.0; + } } impl ::std::ops::BitAnd for Dummy__bindgen_ty_1 { - type - Output - = - Self; + type Output = Self; #[inline] fn bitand(self, other: Self) -> Self { Dummy__bindgen_ty_1(self.0 & other.0) @@ -128,18 +130,23 @@ impl ::std::ops::BitAnd for Dummy__bindgen_ty_1 { } impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { #[inline] - fn bitand_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 &= rhs.0; } + fn bitand_assign(&mut self, rhs: Dummy__bindgen_ty_1) { + self.0 &= rhs.0; + } } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Dummy ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Dummy ) )); -} -impl Clone for Dummy { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Dummy)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Dummy)) + ); } diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index 5606f64e4a..c3209ea5e4 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -5,28 +5,28 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct HasBigBitfield { pub _bitfield_1: [u8; 16usize], } #[test] fn bindgen_test_layout_HasBigBitfield() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( HasBigBitfield ) )); -} -impl Clone for HasBigBitfield { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(HasBigBitfield)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct HasTwoBigBitfields { pub _bitfield_1: [u8; 16usize], } #[test] fn bindgen_test_layout_HasTwoBigBitfields() { - assert_eq!(::std::mem::size_of::() , 16usize , concat - ! ( "Size of: " , stringify ! ( HasTwoBigBitfields ) )); -} -impl Clone for HasTwoBigBitfields { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(HasTwoBigBitfields)) + ); } diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index 9829e4b990..d202893f34 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_1: u8, } @@ -34,11 +34,6 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo8set_typeEc"] pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} impl Foo { #[inline] pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 559f5a38a2..aa718a741d 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub x: ::std::os::raw::c_uchar, pub _bitfield_1: [u8; 2usize], @@ -35,11 +35,6 @@ fn bindgen_test_layout_A() { concat!("Alignment of field: ", stringify!(A), "::", stringify!(y)) ); } -impl Clone for A { - fn clone(&self) -> Self { - *self - } -} impl A { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { @@ -427,7 +422,7 @@ impl A { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct B { pub _bitfield_1: u32, pub __bindgen_align: [u32; 0usize], @@ -445,11 +440,6 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); } -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { @@ -530,7 +520,7 @@ impl B { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct C { pub x: ::std::os::raw::c_uchar, pub _bitfield_1: u8, @@ -559,11 +549,6 @@ fn bindgen_test_layout_C() { concat!("Alignment of field: ", stringify!(C), "::", stringify!(baz)) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl C { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { @@ -644,7 +629,7 @@ impl C { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Date1 { pub _bitfield_1: [u8; 3usize], pub __bindgen_padding_0: u8, @@ -663,11 +648,6 @@ fn bindgen_test_layout_Date1() { concat!("Alignment of ", stringify!(Date1)) ); } -impl Clone for Date1 { - fn clone(&self) -> Self { - *self - } -} impl Date1 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { @@ -827,7 +807,7 @@ impl Date1 { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Date2 { pub _bitfield_1: [u8; 4usize], pub __bindgen_align: [u16; 0usize], @@ -845,11 +825,6 @@ fn bindgen_test_layout_Date2() { concat!("Alignment of ", stringify!(Date2)) ); } -impl Clone for Date2 { - fn clone(&self) -> Self { - *self - } -} impl Date2 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { @@ -1047,7 +1022,7 @@ impl Date2 { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Date3 { pub _bitfield_1: [u8; 3usize], pub byte: ::std::os::raw::c_uchar, @@ -1076,11 +1051,6 @@ fn bindgen_test_layout_Date3() { ) ); } -impl Clone for Date3 { - fn clone(&self) -> Self { - *self - } -} impl Date3 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index d6df314c3b..b10e126f23 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -13,7 +13,7 @@ pub enum MyEnum { FOUR = 3, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct TaggedPtr { pub _bitfield_1: u64, pub __bindgen_align: [u64; 0usize], @@ -31,11 +31,6 @@ fn bindgen_test_layout_TaggedPtr() { concat!("Alignment of ", stringify!(TaggedPtr)) ); } -impl Clone for TaggedPtr { - fn clone(&self) -> Self { - *self - } -} impl Default for TaggedPtr { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs index ee8a4449cd..e5b254cf76 100644 --- a/tests/expectations/tests/bitfield_large_overflow.rs +++ b/tests/expectations/tests/bitfield_large_overflow.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { pub _bindgen_opaque_blob: [u64; 10usize], } @@ -22,11 +22,6 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); } -impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} extern "C" { #[link_name = "\u{1}a"] pub static mut a: _bindgen_ty_1; diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index a56e57f00c..32e61e67f3 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { pub _bitfield_1: u32, pub __bindgen_align: [u32; 0usize], @@ -23,11 +23,6 @@ fn bindgen_test_layout_mach_msg_type_descriptor_t() { concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)) ); } -impl Clone for mach_msg_type_descriptor_t { - fn clone(&self) -> Self { - *self - } -} impl mach_msg_type_descriptor_t { #[inline] pub fn pad3(&self) -> ::std::os::raw::c_uint { diff --git a/tests/expectations/tests/c-empty-layout.rs b/tests/expectations/tests/c-empty-layout.rs index c599b01bac..a14022f54f 100644 --- a/tests/expectations/tests/c-empty-layout.rs +++ b/tests/expectations/tests/c-empty-layout.rs @@ -5,16 +5,18 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] -pub struct Foo { -} +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo {} #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 0usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/tests/expectations/tests/canonical_path_without_namespacing.rs index 8272aebc92..02955e4414 100644 --- a/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -5,19 +5,22 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } extern "C" { #[link_name = "\u{1}_Z3bazPN3foo3BarE"] diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 1e45c74319..9f7834ae9b 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -8,7 +8,7 @@ pub type Char = ::std::os::raw::c_char; pub type SChar = ::std::os::raw::c_schar; pub type UChar = ::std::os::raw::c_uchar; #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Test { pub ch: ::std::os::raw::c_char, pub u: ::std::os::raw::c_uchar, @@ -25,71 +25,134 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::() , 12usize , concat ! ( - "Size of: " , stringify ! ( Test ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Test ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . ch as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( ch ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . u as * const _ as usize } , - 1usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( u ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . d as * const _ as usize } , - 2usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( d ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . cch as * const _ as usize } , - 3usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( cch ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . cu as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( cu ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . cd as * const _ as usize } , - 5usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( cd ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Cch as * const _ as usize } , - 6usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Cch ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Cu as * const _ as usize } , - 7usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Cu ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Cd as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Cd ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Ccch as * const _ as usize } , - 9usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Ccch ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Ccu as * const _ as usize } , - 10usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Ccu ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . Ccd as * const _ as usize } , - 11usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( Ccd ) )); -} -impl Clone for Test { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).ch as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(ch) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).u as *const _ as usize }, + 1usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(u) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).d as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(d) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).cch as *const _ as usize }, + 3usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(cch) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).cu as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(cu) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).cd as *const _ as usize }, + 5usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(cd) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Cch as *const _ as usize }, + 6usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Cch) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Cu as *const _ as usize }, + 7usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Cu) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Cd as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Cd) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Ccch as *const _ as usize }, + 9usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Ccu as *const _ as usize }, + 10usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Ccu) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).Ccd as *const _ as usize }, + 11usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(Ccd) + ) + ); } diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index d7ee8b5207..54751d2e4d 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -7,13 +7,15 @@ #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); -impl __IncompleteArrayField { +impl __IncompleteArrayField { #[inline] pub fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) } + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } #[inline] pub unsafe fn as_mut_ptr(&mut self) -> *mut T { ::std::mem::transmute(self) @@ -27,43 +29,56 @@ impl __IncompleteArrayField { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } -impl ::std::fmt::Debug for __IncompleteArrayField { +impl ::std::fmt::Debug for __IncompleteArrayField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__IncompleteArrayField") } } -impl ::std::clone::Clone for __IncompleteArrayField { +impl ::std::clone::Clone for __IncompleteArrayField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __IncompleteArrayField { } +impl ::std::marker::Copy for __IncompleteArrayField {} #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct C { pub a: ::std::os::raw::c_int, pub big_array: [::std::os::raw::c_char; 33usize], } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 40usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . a as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . big_array as * const _ as usize } - , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( big_array ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).big_array as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); } impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct C_with_zero_length_array { @@ -73,33 +88,53 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - assert_eq!(::std::mem::size_of::() , 40usize , - concat ! ( - "Size of: " , stringify ! ( C_with_zero_length_array ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( C_with_zero_length_array ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C_with_zero_length_array ) ) . a as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - C_with_zero_length_array ) , "::" , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C_with_zero_length_array ) ) . big_array - as * const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( - C_with_zero_length_array ) , "::" , stringify ! ( big_array ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const C_with_zero_length_array ) ) . - zero_length_array as * const _ as usize } , 37usize , concat ! - ( - "Alignment of field: " , stringify ! ( - C_with_zero_length_array ) , "::" , stringify ! ( - zero_length_array ) )); + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + unsafe { &(*(0 as *const C_with_zero_length_array)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C_with_zero_length_array)).big_array as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const C_with_zero_length_array)).zero_length_array as *const _ as usize + }, + 37usize, + concat!( + "Alignment of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); } impl Default for C_with_zero_length_array { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct C_with_incomplete_array { @@ -109,15 +144,21 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { - assert_eq!(::std::mem::size_of::() , 40usize , - concat ! ( - "Size of: " , stringify ! ( C_with_incomplete_array ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( C_with_incomplete_array ) )); + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ); } impl Default for C_with_incomplete_array { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -128,17 +169,27 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { - assert_eq!(::std::mem::size_of::() - , 40usize , concat ! ( - "Size of: " , stringify ! ( - C_with_zero_length_array_and_incomplete_array ) )); - assert_eq! (::std::mem::align_of::() - , 4usize , concat ! ( - "Alignment of " , stringify ! ( - C_with_zero_length_array_and_incomplete_array ) )); + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!( + "Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -147,15 +198,26 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( WithDtor ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithDtor ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithDtor ) , "::" , - stringify ! ( b ) )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithDtor)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -164,19 +226,24 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { - assert_eq!(::std::mem::size_of::() , 8usize , - concat ! ( - "Size of: " , stringify ! ( IncompleteArrayNonCopiable ) )); - assert_eq! (::std::mem::align_of::() , 8usize - , concat ! ( - "Alignment of " , stringify ! ( IncompleteArrayNonCopiable ) - )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ); } impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union Union { pub d: f32, pub i: ::std::os::raw::c_int, @@ -184,92 +251,120 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Union ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Union ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Union ) ) . d as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Union ) , "::" , - stringify ! ( d ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Union ) ) . i as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Union ) , "::" , - stringify ! ( i ) )); -} -impl Clone for Union { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Union)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Union)) + ); + assert_eq!( + unsafe { &(*(0 as *const Union)).d as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Union), + "::", + stringify!(d) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Union)).i as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Union), + "::", + stringify!(i) + ) + ); } impl Default for Union { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct WithUnion { pub data: Union, } #[test] fn bindgen_test_layout_WithUnion() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( WithUnion ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithUnion ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithUnion ) ) . data as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithUnion ) , "::" , - stringify ! ( data ) )); -} -impl Clone for WithUnion { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithUnion)).data as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); } impl Default for WithUnion { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RealAbstractionWithTonsOfMethods { pub _address: u8, } #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!(::std::mem::size_of::() , - 1usize , concat ! ( - "Size of: " , stringify ! ( RealAbstractionWithTonsOfMethods ) - )); - assert_eq! (::std::mem::align_of::() , - 1usize , concat ! ( - "Alignment of " , stringify ! ( - RealAbstractionWithTonsOfMethods ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of ", + stringify!(RealAbstractionWithTonsOfMethods) + ) + ); } extern "C" { #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar(this: - *const RealAbstractionWithTonsOfMethods); + pub fn RealAbstractionWithTonsOfMethods_bar(this: *const RealAbstractionWithTonsOfMethods); } extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1(this: - *mut RealAbstractionWithTonsOfMethods); + pub fn RealAbstractionWithTonsOfMethods_bar1(this: *mut RealAbstractionWithTonsOfMethods); } extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2(this: - *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int); + pub fn RealAbstractionWithTonsOfMethods_bar2( + this: *mut RealAbstractionWithTonsOfMethods, + foo: ::std::os::raw::c_int, + ); } extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] pub fn RealAbstractionWithTonsOfMethods_sta(); } -impl Clone for RealAbstractionWithTonsOfMethods { - fn clone(&self) -> Self { *self } -} impl RealAbstractionWithTonsOfMethods { #[inline] - pub unsafe fn bar(&self) { RealAbstractionWithTonsOfMethods_bar(self) } + pub unsafe fn bar(&self) { + RealAbstractionWithTonsOfMethods_bar(self) + } #[inline] pub unsafe fn bar1(&mut self) { RealAbstractionWithTonsOfMethods_bar1(self) @@ -279,5 +374,7 @@ impl RealAbstractionWithTonsOfMethods { RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] - pub unsafe fn sta() { RealAbstractionWithTonsOfMethods_sta() } + pub unsafe fn sta() { + RealAbstractionWithTonsOfMethods_sta() + } } diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index cb99f81bcf..e9d02479fb 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { pub member_a: ::std::os::raw::c_int, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_B { pub member_b: ::std::os::raw::c_int, } @@ -37,11 +37,6 @@ fn bindgen_test_layout_A_B() { ) ); } -impl Clone for A_B { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_D { @@ -76,13 +71,8 @@ fn bindgen_test_layout_A() { ) ); } -impl Clone for A { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_C { pub baz: ::std::os::raw::c_int, } @@ -109,11 +99,6 @@ fn bindgen_test_layout_A_C() { ) ); } -impl Clone for A_C { - fn clone(&self) -> Self { - *self - } -} extern "C" { #[link_name = "\u{1}var"] pub static mut var: A_B; @@ -125,30 +110,49 @@ fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { 4usize, concat!( "Size of template specialization: ", - stringify ! ( A_D < :: std :: os :: raw :: c_int > ) + stringify!(A_D<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(A_D<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < A_D < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( A_D < :: std :: os :: raw :: c_int > ) ) ); } extern "C" { #[link_name = "\u{1}baz"] pub static mut baz: A_D<::std::os::raw::c_int>; } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct D { pub member: A_B, } #[test] fn bindgen_test_layout_D() { - assert_eq ! ( :: std :: mem :: size_of :: < D > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( D ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < D > ( ) , 4usize , concat ! ( "Alignment of " , stringify ! ( D ) ) ); - assert_eq ! ( unsafe { & ( * ( 0 as * const D ) ) . member as * const _ as usize } , 0usize , concat ! ( "Alignment of field: " , stringify ! ( D ) , "::" , stringify ! ( member ) ) ); -} -impl Clone for D { - fn clone(&self) -> Self { - *self - } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(D)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(D)) + ); + assert_eq!( + unsafe { &(*(0 as *const D)).member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(D), + "::", + stringify!(member) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 7fc05c5fd7..01ae947423 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -5,56 +5,66 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { pub _address: u8, } #[test] fn bindgen_test_layout_whatever() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( whatever ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( whatever ) )); -} -impl Clone for whatever { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(whatever)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(whatever)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child { pub _address: u8, } #[test] fn bindgen_test_layout_whatever_child() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( whatever_child ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( whatever_child ) )); -} -impl Clone for whatever_child { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(whatever_child)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(whatever_child)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_whatever_child_with_member() { - assert_eq!(::std::mem::size_of::() , 4usize , - concat ! ( - "Size of: " , stringify ! ( whatever_child_with_member ) )); - assert_eq! (::std::mem::align_of::() , 4usize - , concat ! ( - "Alignment of " , stringify ! ( whatever_child_with_member ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const whatever_child_with_member ) ) . m_member - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - whatever_child_with_member ) , "::" , stringify ! ( m_member ) - )); -} -impl Clone for whatever_child_with_member { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(whatever_child_with_member)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(whatever_child_with_member)) + ); + assert_eq!( + unsafe { &(*(0 as *const whatever_child_with_member)).m_member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(whatever_child_with_member), + "::", + stringify!(m_member) + ) + ); } diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs index 93ab954258..c28366c134 100644 --- a/tests/expectations/tests/class_static.rs +++ b/tests/expectations/tests/class_static.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct MyClass { pub _address: u8, } @@ -15,18 +15,20 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] - pub static mut MyClass_example_check_no_collision: - *const ::std::os::raw::c_int; + pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } #[test] fn bindgen_test_layout_MyClass() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( MyClass ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( MyClass ) )); -} -impl Clone for MyClass { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(MyClass)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(MyClass)) + ); } extern "C" { #[link_name = "\u{1}_ZL26example_check_no_collision"] diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs index 9a4b542524..c0945c4337 100644 --- a/tests/expectations/tests/class_static_const.rs +++ b/tests/expectations/tests/class_static_const.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { pub _address: u8, } @@ -14,11 +14,14 @@ pub const A_b: i32 = 63; pub const A_c: u32 = 255; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index af73ae3b2a..95b2a7fde0 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -7,7 +7,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { pub replacement: ::std::os::raw::c_int, } @@ -34,13 +34,8 @@ fn bindgen_test_layout_whatever() { ) ); } -impl Clone for whatever { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub c: whatever, } @@ -67,8 +62,3 @@ fn bindgen_test_layout_container() { ) ); } -impl Clone for container { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 03df600838..4848bc1766 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -5,152 +5,213 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct A { pub c: ::std::os::raw::c_uint, pub named_union: A__bindgen_ty_1, pub __bindgen_anon_1: A__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_A_Segment() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( A_Segment ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( A_Segment ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A_Segment ) ) . begin as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A_Segment ) , "::" , - stringify ! ( begin ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A_Segment ) ) . end as * const _ as usize - } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( A_Segment ) , "::" , - stringify ! ( end ) )); -} -impl Clone for A_Segment { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(A_Segment)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A_Segment)) + ); + assert_eq!( + unsafe { &(*(0 as *const A_Segment)).begin as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(A_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const A_Segment)).end as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(A_Segment), + "::", + stringify!(end) + ) + ); } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( A__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( A__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A__bindgen_ty_1 ) ) . f as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A__bindgen_ty_1 ) , - "::" , stringify ! ( f ) )); -} -impl Clone for A__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const A__bindgen_ty_1)).f as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(A__bindgen_ty_1), + "::", + stringify!(f) + ) + ); } impl Default for A__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( A__bindgen_ty_2 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( A__bindgen_ty_2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A__bindgen_ty_2 ) ) . d as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A__bindgen_ty_2 ) , - "::" , stringify ! ( d ) )); -} -impl Clone for A__bindgen_ty_2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_2)) + ); + assert_eq!( + unsafe { &(*(0 as *const A__bindgen_ty_2)).d as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(A__bindgen_ty_2), + "::", + stringify!(d) + ) + ); } impl Default for A__bindgen_ty_2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::
() , 12usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); - assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . c as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A ) , "::" , stringify - ! ( c ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A ) ) . named_union as * const _ as usize - } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( A ) , "::" , stringify - ! ( named_union ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(0 as *const A)).c as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(A), "::", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(0 as *const A)).named_union as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(A), + "::", + stringify!(named_union) + ) + ); } impl Default for A { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct B { pub d: ::std::os::raw::c_uint, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_B_Segment() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( B_Segment ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( B_Segment ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const B_Segment ) ) . begin as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( B_Segment ) , "::" , - stringify ! ( begin ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const B_Segment ) ) . end as * const _ as usize - } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( B_Segment ) , "::" , - stringify ! ( end ) )); -} -impl Clone for B_Segment { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(B_Segment)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B_Segment)) + ); + assert_eq!( + unsafe { &(*(0 as *const B_Segment)).begin as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(B_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const B_Segment)).end as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(B_Segment), + "::", + stringify!(end) + ) + ); } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( B ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( B ) )); - assert_eq! (unsafe { & ( * ( 0 as * const B ) ) . d as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( B ) , "::" , stringify - ! ( d ) )); -} -impl Clone for B { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { &(*(0 as *const B)).d as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(B), "::", stringify!(d)) + ); } #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -161,20 +222,20 @@ pub enum StepSyntax { FunctionalWithEndKeyword = 3, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct C { pub d: ::std::os::raw::c_uint, pub __bindgen_anon_1: C__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union C__bindgen_ty_1 { pub mFunc: C__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_1: C__bindgen_ty_1__bindgen_ty_2, _bindgen_union_align: [u32; 4usize], } #[repr(C)] -#[derive(Debug, Default, Copy, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX1: f32, pub mY1: f32, @@ -183,133 +244,188 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , - 16usize , concat ! ( - "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , - 4usize , concat ! ( - "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 - ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX1 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY1 - as * const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX2 - as * const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX2 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY2 - as * const _ as usize } , 12usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY2 ) - )); -} -impl Clone for C__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY1 as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX2 as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY2 as *const _ as usize }, + 12usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2) + ) + ); } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::() , 8usize - , concat ! ( - "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 ) )); - assert_eq! (::std::mem::align_of::() , - 4usize , concat ! ( - "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 - ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) . - mStepSyntax as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( - mStepSyntax ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) . - mSteps as * const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( - C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( mSteps - ) )); -} -impl Clone for C__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mStepSyntax as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mSteps as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps) + ) + ); } impl Default for C__bindgen_ty_1__bindgen_ty_2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( C__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( C__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C__bindgen_ty_1 ) ) . mFunc as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C__bindgen_ty_1 ) , - "::" , stringify ! ( mFunc ) )); -} -impl Clone for C__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const C__bindgen_ty_1)).mFunc as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc) + ) + ); } impl Default for C__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_C_Segment() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( C_Segment ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( C_Segment ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C_Segment ) ) . begin as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C_Segment ) , "::" , - stringify ! ( begin ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C_Segment ) ) . end as * const _ as usize - } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( C_Segment ) , "::" , - stringify ! ( end ) )); -} -impl Clone for C_Segment { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C_Segment)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_Segment)) + ); + assert_eq!( + unsafe { &(*(0 as *const C_Segment)).begin as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C_Segment)).end as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C_Segment), + "::", + stringify!(end) + ) + ); } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 20usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( d ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 20usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).d as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(d)) + ); } impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 480b6b34be..459d580c47 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -6,7 +6,7 @@ pub type AnotherInt = ::std::os::raw::c_int; #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct C { pub c: C_MyInt, pub ptr: *mut C_MyInt, @@ -18,33 +18,46 @@ pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 72usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . c as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( c ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . ptr as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( ptr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . arr as * const _ as usize } , - 16usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( arr ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize - } , 56usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( d ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . other_ptr as * const _ as usize } - , 64usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( other_ptr ) )); + assert_eq!( + ::std::mem::size_of::(), + 72usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).c as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).ptr as *const _ as usize }, + 8usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(ptr)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).arr as *const _ as usize }, + 16usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(arr)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).d as *const _ as usize }, + 56usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(d)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).other_ptr as *const _ as usize }, + 64usize, + concat!( + "Alignment of field: ", + stringify!(C), + "::", + stringify!(other_ptr) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] @@ -62,15 +75,16 @@ extern "C" { #[link_name = "\u{1}_ZN1C13anotherMethodEi"] pub fn C_anotherMethod(this: *mut C, c: AnotherInt); } -impl Clone for C { - fn clone(&self) -> Self { *self } -} impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } impl C { #[inline] - pub unsafe fn method(&mut self, c: C_MyInt) { C_method(self, c) } + pub unsafe fn method(&mut self, c: C_MyInt) { + C_method(self, c) + } #[inline] pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) { C_methodRef(self, c) @@ -85,26 +99,31 @@ impl C { } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct D { pub _base: C, pub ptr: *mut C_MyInt, } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::() , 80usize , concat ! ( - "Size of: " , stringify ! ( D ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( D ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const D ) ) . ptr as * const _ as usize } , - 72usize , concat ! ( - "Alignment of field: " , stringify ! ( D ) , "::" , stringify - ! ( ptr ) )); -} -impl Clone for D { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 80usize, + concat!("Size of: ", stringify!(D)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(D)) + ); + assert_eq!( + unsafe { &(*(0 as *const D)).ptr as *const _ as usize }, + 72usize, + concat!("Alignment of field: ", stringify!(D), "::", stringify!(ptr)) + ); } impl Default for D { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index 127c1b0e07..4fe2b5eb50 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -12,7 +12,7 @@ pub mod root { /// /// This class is really really interesting, look! #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -20,29 +20,35 @@ pub mod root { /// /// This class is not so interesting, but worth a bit of docs too! #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Foo_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo_Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo_Bar ) )); - } - impl Clone for Foo_Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo_Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo_Bar)) + ); } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); - } - impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } pub mod test { #[allow(unused_imports)] @@ -50,7 +56,7 @@ pub mod root { /// I'm in a namespace, and thus I may be on a rust module, most of the time. /// My documentation is pretty extensive, I guess. #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Baz { /// This member is plain awesome, just amazing. /// @@ -63,52 +69,66 @@ pub mod root { } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Baz ) ) . member as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Baz ) , "::" , - stringify ! ( member ) )); - } - impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)) + ); + assert_eq!( + unsafe { &(*(0 as *const Baz)).member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Baz), + "::", + stringify!(member) + ) + ); } /// I'm in an inline namespace, and as such I shouldn't get generated inside /// a rust module, except when the relevant option is specified. Also, this /// comment shouldn't be misaligned. #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct InInlineNS { pub _address: u8, } #[test] fn bindgen_test_layout_InInlineNS() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! - ( "Size of: " , stringify ! ( InInlineNS ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat - ! ( "Alignment of " , stringify ! ( InInlineNS ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(InInlineNS)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InInlineNS)) + ); } - impl Clone for InInlineNS { - fn clone(&self) -> Self { *self } - } - + #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bazz { pub _address: u8, } #[test] fn bindgen_test_layout_Bazz() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bazz ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bazz ) )); - } - impl Clone for Bazz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bazz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bazz)) + ); } } } diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 6159f979a0..02c8714c5a 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -11,88 +11,124 @@ pub struct __BindgenComplex { pub im: T, } #[repr(C)] -#[derive(Debug, Default, Copy, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct TestDouble { pub mMember: __BindgenComplex, } #[test] fn bindgen_test_layout_TestDouble() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( TestDouble ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( TestDouble ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const TestDouble ) ) . mMember as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( TestDouble ) , "::" , - stringify ! ( mMember ) )); -} -impl Clone for TestDouble { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(TestDouble)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestDouble)) + ); + assert_eq!( + unsafe { &(*(0 as *const TestDouble)).mMember as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(TestDouble), + "::", + stringify!(mMember) + ) + ); } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestDoublePtr { pub mMember: *mut __BindgenComplex, } #[test] fn bindgen_test_layout_TestDoublePtr() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( TestDoublePtr ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( TestDoublePtr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const TestDoublePtr ) ) . mMember as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( TestDoublePtr ) , "::" - , stringify ! ( mMember ) )); -} -impl Clone for TestDoublePtr { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestDoublePtr)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestDoublePtr)) + ); + assert_eq!( + unsafe { &(*(0 as *const TestDoublePtr)).mMember as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(TestDoublePtr), + "::", + stringify!(mMember) + ) + ); } impl Default for TestDoublePtr { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct TestFloat { pub mMember: __BindgenComplex, } #[test] fn bindgen_test_layout_TestFloat() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( TestFloat ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( TestFloat ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const TestFloat ) ) . mMember as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( TestFloat ) , "::" , - stringify ! ( mMember ) )); -} -impl Clone for TestFloat { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestFloat)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(TestFloat)) + ); + assert_eq!( + unsafe { &(*(0 as *const TestFloat)).mMember as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(TestFloat), + "::", + stringify!(mMember) + ) + ); } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestFloatPtr { pub mMember: *mut __BindgenComplex, } #[test] fn bindgen_test_layout_TestFloatPtr() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( TestFloatPtr ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( TestFloatPtr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const TestFloatPtr ) ) . mMember as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( TestFloatPtr ) , "::" , - stringify ! ( mMember ) )); -} -impl Clone for TestFloatPtr { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestFloatPtr)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestFloatPtr)) + ); + assert_eq!( + unsafe { &(*(0 as *const TestFloatPtr)).mMember as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(TestFloatPtr), + "::", + stringify!(mMember) + ) + ); } impl Default for TestFloatPtr { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index 98c6240fa2..539c8916c6 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -8,23 +8,31 @@ pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { FOO_BAR = 0, FOO_BAZ = 1, } +pub enum _bindgen_ty_1 { + FOO_BAR = 0, + FOO_BAZ = 1, +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } +pub enum Foo__bindgen_ty_1 { + FOO_BAR = 10, +} #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index af13e079d8..3b37daf301 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -9,7 +9,7 @@ pub const foo_SHOULD_BE: foo = 1; pub const foo_A_CONSTANT: foo = 2; pub type foo = ::std::os::raw::c_uint; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct bar { pub this_should_work: foo, } @@ -36,11 +36,6 @@ fn bindgen_test_layout_bar() { ) ); } -impl Clone for bar { - fn clone(&self) -> Self { - *self - } -} impl Default for bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index bfe33c6b56..6c56e2ec52 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -13,7 +13,7 @@ pub mod foo { pub use self::foo::Type as foo_alias1; pub use self::foo_alias1 as foo_alias2; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct bar { pub this_should_work: foo::Type, } @@ -40,11 +40,6 @@ fn bindgen_test_layout_bar() { ) ); } -impl Clone for bar { - fn clone(&self) -> Self { - *self - } -} impl Default for bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index 4db009be78..b09f837dd7 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -25,27 +25,37 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Copy, Clone)] pub struct bar { pub this_should_work: root::ns1::ns2::foo::Type, } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . this_should_work as - * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , - "::" , stringify ! ( this_should_work ) )); - } - impl Clone for bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).this_should_work as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); } impl Default for bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } } } diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 9b5fd7b88c..1f2b4b2ffa 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -12,25 +12,35 @@ pub mod foo { pub const Type__: Type = 3; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct bar { pub member: foo::Type, } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member ) )); -} -impl Clone for bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member) + ) + ); } impl Default for bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 75c952d7d2..0387ddd06d 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -14,7 +14,7 @@ pub use self::Foo::Type as Foo_alias1; pub use self::Foo_alias1 as Foo_alias2; pub use self::Foo_alias2 as Foo_alias3; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Bar { pub baz1: Foo::Type, pub baz2: Foo_alias1, @@ -118,11 +118,6 @@ fn bindgen_test_layout_Bar() { ) ); } -impl Clone for Bar { - fn clone(&self) -> Self { - *self - } -} impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 4f8d46c5e8..7fb4606f20 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -10,31 +10,46 @@ pub mod one_Foo { pub const Variant2: Type = 1; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Bar { pub baz1: one_Foo::Type, pub baz2: *mut one_Foo::Type, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz1 as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz2 as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz2 ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz2 as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz2) + ) + ); } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index 0c25780b8f..cc1f3d4cd6 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -37,7 +37,7 @@ pub use self::anon_enum::Type as anon_enum_alias1; pub use self::anon_enum_alias1 as anon_enum_alias2; pub use self::anon_enum_alias2 as anon_enum_alias3; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct bar { pub member1: foo::Type, pub member2: foo_alias1, @@ -52,89 +52,154 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::() , 48usize , concat ! ( - "Size of: " , stringify ! ( bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member1 as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member2 as * const _ as usize } - , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member3 as * const _ as usize } - , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member3 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member4 as * const _ as usize } - , 12usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member4 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member5 as * const _ as usize } - , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member5 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member6 as * const _ as usize } - , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member6 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member7 as * const _ as usize } - , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member7 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member8 as * const _ as usize } - , 36usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member8 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member9 as * const _ as usize } - , 40usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member9 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . member10 as * const _ as usize - } , 44usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( member10 ) )); -} -impl Clone for bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member2 as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member2) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member3 as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member3) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member4 as *const _ as usize }, + 12usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member4) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member5 as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member5) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member6 as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member6) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member7 as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member7) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member8 as *const _ as usize }, + 36usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member8) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member9 as *const _ as usize }, + 40usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member9) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).member10 as *const _ as usize }, + 44usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(member10) + ) + ); } impl Default for bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Baz { pub member1: ns2_Foo::Type, } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Baz ) ) . member1 as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Baz ) , "::" , - stringify ! ( member1 ) )); -} -impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)) + ); + assert_eq!( + unsafe { &(*(0 as *const Baz)).member1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Baz), + "::", + stringify!(member1) + ) + ); } impl Default for Baz { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub mod one_Foo { pub type Type = ::std::os::raw::c_int; @@ -142,37 +207,53 @@ pub mod one_Foo { pub const Variant2: Type = 1; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Bar { pub baz: *mut one_Foo::Type, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_Z5func13fooPS_PS0_"] - pub fn func1(arg1: foo::Type, arg2: *mut foo::Type, - arg3: *mut *mut foo::Type) -> *mut foo::Type; + pub fn func1( + arg1: foo::Type, + arg2: *mut foo::Type, + arg3: *mut *mut foo::Type, + ) -> *mut foo::Type; } extern "C" { #[link_name = "\u{1}_Z5func23fooPS_PS0_"] - pub fn func2(arg1: foo_alias1, arg2: *mut foo_alias1, - arg3: *mut *mut foo_alias1) -> *mut foo_alias1; + pub fn func2( + arg1: foo_alias1, + arg2: *mut foo_alias1, + arg3: *mut *mut foo_alias1, + ) -> *mut foo_alias1; } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -180,8 +261,10 @@ pub struct Thing { pub thing: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Thing { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for Thing { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_Z5func35ThingI3fooE"] diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index 534f70e3f3..7336024850 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -10,24 +10,27 @@ pub struct Foo { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } extern "C" { #[link_name = "\u{1}_ZN3BarC1Ev"] pub fn Bar_Bar(this: *mut Bar); } -impl Clone for Bar { - fn clone(&self) -> Self { *self } -} impl Bar { #[inline] pub unsafe fn new() -> Self { diff --git a/tests/expectations/tests/constructors.rs b/tests/expectations/tests/constructors.rs index bb0d294a14..b20e3f44d5 100644 --- a/tests/expectations/tests/constructors.rs +++ b/tests/expectations/tests/constructors.rs @@ -5,29 +5,31 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct TestOverload { pub _address: u8, } #[test] fn bindgen_test_layout_TestOverload() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( TestOverload ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( TestOverload ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestOverload)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestOverload)) + ); } extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ei"] - pub fn TestOverload_TestOverload(this: *mut TestOverload, - arg1: ::std::os::raw::c_int); + pub fn TestOverload_TestOverload(this: *mut TestOverload, arg1: ::std::os::raw::c_int); } extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ed"] pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64); } -impl Clone for TestOverload { - fn clone(&self) -> Self { *self } -} impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { @@ -43,24 +45,27 @@ impl TestOverload { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct TestPublicNoArgs { pub _address: u8, } #[test] fn bindgen_test_layout_TestPublicNoArgs() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( TestPublicNoArgs ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( TestPublicNoArgs ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestPublicNoArgs)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestPublicNoArgs)) + ); } extern "C" { #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"] pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs); } -impl Clone for TestPublicNoArgs { - fn clone(&self) -> Self { *self } -} impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 08570f16db..b471386a92 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -7,7 +7,7 @@ pub type mbedtls_mpi_uint = ::std::os::raw::c_uint; /// \brief MPI structure #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct mbedtls_mpi { /// < integer sign pub s: ::std::os::raw::c_int, @@ -18,29 +18,49 @@ pub struct mbedtls_mpi { } #[test] fn bindgen_test_layout_mbedtls_mpi() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of: " , stringify ! ( mbedtls_mpi ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( mbedtls_mpi ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mbedtls_mpi ) ) . s as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" , - stringify ! ( s ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mbedtls_mpi ) ) . n as * const _ as usize - } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" , - stringify ! ( n ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mbedtls_mpi ) ) . p as * const _ as usize - } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" , - stringify ! ( p ) )); -} -impl Clone for mbedtls_mpi { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(mbedtls_mpi)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(mbedtls_mpi)) + ); + assert_eq!( + unsafe { &(*(0 as *const mbedtls_mpi)).s as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(mbedtls_mpi), + "::", + stringify!(s) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const mbedtls_mpi)).n as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(mbedtls_mpi), + "::", + stringify!(n) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const mbedtls_mpi)).p as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(mbedtls_mpi), + "::", + stringify!(p) + ) + ); } impl Default for mbedtls_mpi { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 906da262ba..87554a2c1a 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -11,7 +11,7 @@ pub struct __BindgenComplex { pub im: T, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct foo { pub bar: ::std::os::raw::c_float, pub baz: ::std::os::raw::c_float, @@ -22,44 +22,79 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 48usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , 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 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( baz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . bazz as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( bazz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . bazzz as * const _ as usize } , - 16usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( bazzz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . complexFloat as * const _ as - usize } , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( complexFloat ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . complexDouble as * const _ as - usize } , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( complexDouble ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + 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) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).baz as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(baz) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).bazz as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(bazz) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).bazzz as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(bazzz) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).complexFloat as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(complexFloat) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).complexDouble as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(complexDouble) + ) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/cpp-empty-layout.rs b/tests/expectations/tests/cpp-empty-layout.rs index c894b95c97..36cae7222f 100644 --- a/tests/expectations/tests/cpp-empty-layout.rs +++ b/tests/expectations/tests/cpp-empty-layout.rs @@ -5,17 +5,20 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index f2b1dbd853..c56cceb2e8 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -10,19 +10,22 @@ pub struct Base { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Derived { pub _address: u8, } #[test] fn bindgen_test_layout_Derived() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Derived ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Derived ) )); -} -impl Clone for Derived { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Derived)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Derived)) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -36,30 +39,47 @@ pub struct DerivedFromBaseWithDestructor { } #[test] fn bindgen_test_layout_DerivedFromBaseWithDestructor() { - assert_eq!(::std::mem::size_of::() , 1usize - , concat ! ( - "Size of: " , stringify ! ( DerivedFromBaseWithDestructor ) )); - assert_eq! (::std::mem::align_of::() , - 1usize , concat ! ( - "Alignment of " , stringify ! ( DerivedFromBaseWithDestructor - ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)) + ); } #[test] fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( Base ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Base ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Base)) + ); } #[test] -fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! - ( - "Size of template specialization: " , stringify ! ( - BaseWithDestructor ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat - ! ( - "Alignment of template specialization: " , stringify ! ( - BaseWithDestructor ) )); +fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation( +) { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithDestructor) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithDestructor) + ) + ); } diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 143a6ce40a..620508866c 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -9,7 +9,7 @@ /// and --with-derive-partialeq --impl-partialeq --impl-debug is provided, /// this struct should manually implement `Debug` and `PartialEq`. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Foo { pub large: [::std::os::raw::c_int; 33usize], pub _bitfield_1: [u8; 2usize], @@ -50,11 +50,6 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo8set_typeEc"] pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs new file mode 100644 index 0000000000..356d93e336 --- /dev/null +++ b/tests/expectations/tests/derive-clone.rs @@ -0,0 +1,41 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + + +/// This struct should derive `Clone`. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ShouldDeriveClone { + pub large: [::std::os::raw::c_int; 33usize], +} +#[test] +fn bindgen_test_layout_ShouldDeriveClone() { + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(ShouldDeriveClone)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldDeriveClone)) + ); + assert_eq!( + unsafe { &(*(0 as *const ShouldDeriveClone)).large as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ShouldDeriveClone), + "::", + stringify!(large) + ) + ); +} +impl Default for ShouldDeriveClone { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs new file mode 100644 index 0000000000..2ead68ee1d --- /dev/null +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -0,0 +1,47 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + + +/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct +/// should impl `Clone` "manually". +#[repr(C)] +#[derive(Copy)] +pub struct ShouldImplClone { + pub large: [::std::os::raw::c_int; 33usize], +} +#[test] +fn bindgen_test_layout_ShouldImplClone() { + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(ShouldImplClone)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldImplClone)) + ); + assert_eq!( + unsafe { &(*(0 as *const ShouldImplClone)).large as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ShouldImplClone), + "::", + stringify!(large) + ) + ); +} +impl Clone for ShouldImplClone { + fn clone(&self) -> Self { + *self + } +} +impl Default for ShouldImplClone { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 53fcf716a3..d664a4bafe 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct C { pub _bitfield_1: u8, pub large_array: [::std::os::raw::c_int; 50usize], @@ -33,11 +33,6 @@ fn bindgen_test_layout_C() { ) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index 03cafe9769..01ffe206ac 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -5,43 +5,61 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Nice { pub pointer: Nice_Function, pub large_array: [::std::os::raw::c_int; 34usize], } -pub type Nice_Function = - ::std::option::Option; +pub type Nice_Function = ::std::option::Option; #[test] fn bindgen_test_layout_Nice() { - assert_eq!(::std::mem::size_of::() , 144usize , concat ! ( - "Size of: " , stringify ! ( Nice ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Nice ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Nice ) ) . pointer as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Nice ) , "::" , - stringify ! ( pointer ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Nice ) ) . large_array as * const _ as - usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( Nice ) , "::" , - stringify ! ( large_array ) )); -} -impl Clone for Nice { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 144usize, + concat!("Size of: ", stringify!(Nice)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Nice)) + ); + assert_eq!( + unsafe { &(*(0 as *const Nice)).pointer as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Nice), + "::", + stringify!(pointer) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Nice)).large_array as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(Nice), + "::", + stringify!(large_array) + ) + ); } impl Default for Nice { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } impl ::std::fmt::Debug for Nice { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - write!(f , "Nice {{ pointer: {:?}, large_array: [{}] }}" , self . - pointer , self . large_array . iter ( ) . enumerate ( ) . map - ( - | ( i , v ) | format ! ( - "{}{:?}" , if i > 0 { ", " } else { "" } , v ) ) . collect :: < - String > ( )) + write!( + f, + "Nice {{ pointer: {:?}, large_array: [{}] }}", + self.pointer, + self.large_array + .iter() + .enumerate() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::() + ) } } diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index ac4792969e..382d906359 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -4,79 +4,105 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub type my_fun_t = - ::std::option::Option; +pub type my_fun_t = ::std::option::Option< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + arg4: ::std::os::raw::c_int, + arg5: ::std::os::raw::c_int, + arg6: ::std::os::raw::c_int, + arg7: ::std::os::raw::c_int, + arg8: ::std::os::raw::c_int, + arg9: ::std::os::raw::c_int, + arg10: ::std::os::raw::c_int, + arg11: ::std::os::raw::c_int, + arg12: ::std::os::raw::c_int, + arg13: ::std::os::raw::c_int, + arg14: ::std::os::raw::c_int, + arg15: ::std::os::raw::c_int, + arg16: ::std::os::raw::c_int, + ), +>; #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Foo { pub callback: my_fun_t, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Foo ) ) . callback as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Foo ) , "::" , - stringify ! ( callback ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const Foo)).callback as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Foo), + "::", + stringify!(callback) + ) + ); } impl Default for Foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } -pub type my_fun2_t = - ::std::option::Option; +pub type my_fun2_t = ::std::option::Option< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + arg4: ::std::os::raw::c_int, + arg5: ::std::os::raw::c_int, + arg6: ::std::os::raw::c_int, + arg7: ::std::os::raw::c_int, + arg8: ::std::os::raw::c_int, + arg9: ::std::os::raw::c_int, + arg10: ::std::os::raw::c_int, + arg11: ::std::os::raw::c_int, + arg12: ::std::os::raw::c_int, + ), +>; #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub callback: my_fun2_t, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . callback as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( callback ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).callback as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(callback) + ) + ); } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + 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 index 6436b69a93..b4f93f73ee 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -7,12 +7,12 @@ /// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] -#[derive(Debug, Default, Copy, PartialOrd, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, PartialOrd, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo__bindgen_ty_1 { pub a: f32, pub b: f32, @@ -50,11 +50,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); } -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} #[test] fn bindgen_test_layout_foo() { assert_eq!( @@ -78,8 +73,3 @@ fn bindgen_test_layout_foo() { ) ); } -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 index dd9acc6a1f..d736c11426 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -7,7 +7,7 @@ /// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] -#[derive(Debug, Default, Copy, PartialOrd, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { pub bar: [f32; 3usize], } @@ -34,8 +34,3 @@ fn bindgen_test_layout_foo() { ) ); } -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 index b2ae7ab223..7ff50fcf5b 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -7,7 +7,7 @@ /// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq #[repr(C)] -#[derive(Debug, Copy, Hash, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct ConstPtrMutObj { pub bar: *const ::std::os::raw::c_int, } @@ -34,18 +34,13 @@ fn bindgen_test_layout_ConstPtrMutObj() { ) ); } -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, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct MutPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } @@ -72,18 +67,13 @@ fn bindgen_test_layout_MutPtrMutObj() { ) ); } -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, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct MutPtrConstObj { pub bar: *const ::std::os::raw::c_int, } @@ -110,18 +100,13 @@ fn bindgen_test_layout_MutPtrConstObj() { ) ); } -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, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct ConstPtrConstObj { pub bar: *const ::std::os::raw::c_int, } @@ -148,11 +133,6 @@ fn bindgen_test_layout_ConstPtrConstObj() { ) ); } -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-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index 6473bebaab..4fd935aa71 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -19,7 +19,7 @@ impl Default for foo { } /// Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int #[repr(C)] -#[derive(Debug, Copy, Hash, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct IntStr { pub a: foo<::std::os::raw::c_int>, } @@ -46,11 +46,6 @@ fn bindgen_test_layout_IntStr() { ) ); } -impl Clone for IntStr { - fn clone(&self) -> Self { - *self - } -} impl Default for IntStr { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -58,7 +53,7 @@ impl Default for IntStr { } /// Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd #[repr(C)] -#[derive(Debug, Copy, PartialOrd, PartialEq)] +#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] pub struct FloatStr { pub a: foo, } @@ -85,11 +80,6 @@ fn bindgen_test_layout_FloatStr() { ) ); } -impl Clone for FloatStr { - fn clone(&self) -> Self { - *self - } -} impl Default for FloatStr { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index 6e3446d52f..73972d70d7 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_mbuf { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { _bindgen_union_align: [u8; 0usize], } @@ -27,11 +27,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); } -impl Clone for rte_mbuf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -45,11 +40,6 @@ fn bindgen_test_layout_rte_mbuf() { concat!("Size of: ", stringify!(rte_mbuf)) ); } -impl Clone for rte_mbuf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index 1235665522..cb86ebe68d 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Base { pub large: [::std::os::raw::c_int; 33usize], } @@ -32,11 +32,6 @@ fn bindgen_test_layout_Base() { ) ); } -impl Clone for Base { - fn clone(&self) -> Self { - *self - } -} impl Default for Base { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -48,7 +43,7 @@ impl ::std::cmp::PartialEq for Base { } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct ShouldDerivePartialEq { pub _base: Base, } @@ -65,11 +60,6 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); } -impl Clone for ShouldDerivePartialEq { - fn clone(&self) -> Self { - *self - } -} impl Default for ShouldDerivePartialEq { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index bc7e750ea5..b9e2db2917 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct C { pub _bitfield_1: u8, pub large_array: [::std::os::raw::c_int; 50usize], @@ -33,11 +33,6 @@ fn bindgen_test_layout_C() { ) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 1660f17877..7b925fba7b 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -6,7 +6,7 @@ extern crate core; #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct C { pub large_array: [::std::os::raw::c_int; 420usize], } @@ -33,11 +33,6 @@ fn bindgen_test_layout_C() { ) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl Default for C { fn default() -> Self { unsafe { ::core::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index b1d3f04c6d..52a4bf7149 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub b: *mut a, } @@ -27,23 +27,18 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(b)) ); } -impl Clone for Bar { - fn clone(&self) -> Self { - *self - } -} impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct c { pub __bindgen_anon_1: c__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union c__bindgen_ty_1 { _bindgen_union_align: u8, pub _address: u8, @@ -61,11 +56,6 @@ fn bindgen_test_layout_c__bindgen_ty_1() { concat!("Alignment of ", stringify!(c__bindgen_ty_1)) ); } -impl Clone for c__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for c__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -84,18 +74,13 @@ fn bindgen_test_layout_c() { concat!("Alignment of ", stringify!(c)) ); } -impl Clone for c { - fn clone(&self) -> Self { - *self - } -} impl Default for c { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct a { pub d: c, } @@ -117,11 +102,6 @@ fn bindgen_test_layout_a() { concat!("Alignment of field: ", stringify!(a), "::", stringify!(d)) ); } -impl Clone for a { - fn clone(&self) -> Self { - *self - } -} impl Default for a { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index 975dee3670..c264206287 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -7,7 +7,7 @@ /// Deriving PartialEq for rust unions is not supported. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, pub b: ::std::os::raw::c_int, @@ -46,11 +46,6 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { ) ); } -impl Clone for ShouldNotDerivePartialEq { - fn clone(&self) -> Self { - *self - } -} impl Default for ShouldNotDerivePartialEq { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 292533d995..2da07dedb0 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -5,39 +5,50 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Doggo { pub x: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Doggo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Doggo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Doggo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Doggo ) ) . x as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Doggo ) , "::" , - stringify ! ( x ) )); -} -impl Clone for Doggo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Doggo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Doggo)) + ); + assert_eq!( + unsafe { &(*(0 as *const Doggo)).x as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Doggo), + "::", + stringify!(x) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Null { pub _address: u8, } #[test] fn bindgen_test_layout_Null() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Null ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Null ) )); -} -impl Clone for Null { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Null)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Null)) + ); } /// This type is an opaque union. Unions can't derive anything interesting like /// Debug or Default, even if their layout can, because it would require knowing @@ -46,20 +57,25 @@ impl Clone for Null { /// probably emit an opaque struct for opaque unions... but until then, we have /// this test to make sure that opaque unions don't derive and still compile. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union DoggoOrNull { pub _bindgen_opaque_blob: u32, } #[test] fn bindgen_test_layout_DoggoOrNull() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( DoggoOrNull ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( DoggoOrNull ) )); -} -impl Clone for DoggoOrNull { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(DoggoOrNull)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(DoggoOrNull)) + ); } impl Default for DoggoOrNull { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 67ca77d66f..9732849c81 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -12,57 +12,80 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub foo: ::std::os::raw::c_int, pub baz: bool, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . foo as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz ) )); - } - impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).foo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } pub mod bar { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Copy, Clone)] pub struct Foo { pub ptr: *mut root::foo::Bar, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Foo ) ) . ptr as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Foo ) , "::" , - stringify ! ( ptr ) )); - } - impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const Foo)).ptr as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Foo), + "::", + stringify!(ptr) + ) + ); } impl Default for Foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } } } diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index b3e49f4f8f..ffdcedd5e6 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -8,31 +8,40 @@ pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, } +pub enum _bindgen_ty_1 { + match_ = 0, + whatever_else = 1, +} #[repr(C)] pub struct C__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct C { pub vtable_: *const C__bindgen_vtable, pub i: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . i as * const _ as usize - } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( i ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).i as *const _ as usize }, + 8usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(i)) + ); } impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_ZN1C5matchEv"] diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 6b07841844..8ad45f10e9 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -21,7 +21,7 @@ impl Default for RefPtr { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Bar { pub m_member: RefPtr, } @@ -48,11 +48,6 @@ fn bindgen_test_layout_Bar() { ) ); } -impl Clone for Bar { - fn clone(&self) -> Self { - *self - } -} impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -63,10 +58,14 @@ fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { assert_eq!( ::std::mem::size_of::>(), 8usize, + concat!("Size of template specialization: ", stringify!(RefPtr)) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, concat!( - "Size of template specialization: ", - stringify ! ( RefPtr < Foo > ) + "Alignment of template specialization: ", + stringify!(RefPtr) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < RefPtr < Foo > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( RefPtr < Foo > ) ) ); } diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index e02ba76cb8..ceab52d744 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -5,19 +5,22 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo_empty { pub _address: u8, } #[test] fn bindgen_test_layout_Foo_empty() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo_empty ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo_empty ) )); -} -impl Clone for Foo_empty { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo_empty)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo_empty)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -25,27 +28,32 @@ pub struct Foo { _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Bar { pub f: *mut Foo, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . f as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( f ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).f as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(f)) + ); } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_Z10baz_structP3Foo"] diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index a0f0c13726..001d6df096 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -5,40 +5,48 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct a { pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( a ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( a ) )); - assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , stringify - ! ( b ) )); -} -impl Clone for a { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(a), "::", stringify!(b)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct c { pub d: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_c() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( c ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( c ) )); - assert_eq! (unsafe { & ( * ( 0 as * const c ) ) . d as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( c ) , "::" , stringify - ! ( d ) )); -} -impl Clone for c { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(c)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(0 as *const c)).d as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(c), "::", stringify!(d)) + ); } diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index e3d1abffe0..5a2c00c73f 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -5,31 +5,39 @@ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum baz { } +pub enum baz {} #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { - pub bar: ::std::option::Option baz>, + pub bar: ::std::option::Option< + unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz, + >, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + 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 Default for Foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/gen-constructors-neg.rs b/tests/expectations/tests/gen-constructors-neg.rs index c894b95c97..36cae7222f 100644 --- a/tests/expectations/tests/gen-constructors-neg.rs +++ b/tests/expectations/tests/gen-constructors-neg.rs @@ -5,17 +5,20 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/gen-constructors.rs b/tests/expectations/tests/gen-constructors.rs index 07fded03c2..cb2024a16b 100644 --- a/tests/expectations/tests/gen-constructors.rs +++ b/tests/expectations/tests/gen-constructors.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -26,11 +26,6 @@ extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} impl Foo { #[inline] pub unsafe fn new(a: ::std::os::raw::c_int) -> Self { diff --git a/tests/expectations/tests/generate-inline.rs b/tests/expectations/tests/generate-inline.rs index f123acef92..48d8f4f898 100644 --- a/tests/expectations/tests/generate-inline.rs +++ b/tests/expectations/tests/generate-inline.rs @@ -5,27 +5,32 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } extern "C" { #[link_name = "\u{1}_ZN3Foo3barEv"] pub fn Foo_bar() -> ::std::os::raw::c_int; } -impl Clone for Foo { - fn clone(&self) -> Self { *self } -} impl Foo { #[inline] - pub unsafe fn bar() -> ::std::os::raw::c_int { Foo_bar() } + pub unsafe fn bar() -> ::std::os::raw::c_int { + Foo_bar() + } } extern "C" { #[link_name = "\u{1}_Z3foov"] diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs index 85af3e03af..49e842d7c6 100644 --- a/tests/expectations/tests/inherit_typedef.rs +++ b/tests/expectations/tests/inherit_typedef.rs @@ -5,33 +5,39 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } pub type TypedefedFoo = Foo; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 13f3b8ee7c..ade3ce3bb6 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -14,23 +14,31 @@ pub mod root { pub type Ty = ::std::os::raw::c_int; } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub baz: root::foo::Ty, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz ) )); - } - impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 406d9f5ece..7895a19f5f 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -19,23 +19,31 @@ pub mod root { pub type Ty = ::std::os::raw::c_longlong; } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub baz: root::foo::bar::Ty, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( baz ) )); - } - impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 1315bb6ac9..3ea87edb33 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub bar: ::std::os::raw::c_int, } @@ -19,16 +19,24 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index b94ba60f70..bf39e06514 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -11,37 +11,56 @@ pub struct LinkedList { pub prev: *mut LinkedList, } impl Default for LinkedList { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct InstantiateIt { pub m_list: LinkedList, } #[test] fn bindgen_test_layout_InstantiateIt() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( InstantiateIt ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( InstantiateIt ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const InstantiateIt ) ) . m_list as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( InstantiateIt ) , "::" - , stringify ! ( m_list ) )); -} -impl Clone for InstantiateIt { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(InstantiateIt)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InstantiateIt)) + ); + assert_eq!( + unsafe { &(*(0 as *const InstantiateIt)).m_list as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(InstantiateIt), + "::", + stringify!(m_list) + ) + ); } impl Default for InstantiateIt { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of template specialization: " , stringify ! ( LinkedList - ) )); - assert_eq!(::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - LinkedList ) )); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of template specialization: ", stringify!(LinkedList)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(LinkedList) + ) + ); } diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index 9073d928f2..b0c4b52959 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct S2 { pub _bitfield_1: u16, } @@ -22,11 +22,6 @@ fn bindgen_test_layout_S2() { concat!("Alignment of ", stringify!(S2)) ); } -impl Clone for S2 { - fn clone(&self) -> Self { - *self - } -} impl S2 { #[inline] pub fn new_bitfield_1() -> u16 { diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 6924d0a9d7..84a33cb9a7 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -9,7 +9,7 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Copy, Clone)] pub struct i { pub j: *mut root::i, pub k: *mut root::i, @@ -17,54 +17,64 @@ pub mod root { } #[test] fn bindgen_test_layout_i() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of: " , stringify ! ( i ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( i ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const i ) ) . j as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( i ) , "::" , - stringify ! ( j ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const i ) ) . k as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( i ) , "::" , - stringify ! ( k ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const i ) ) . l as * const _ as usize } , - 16usize , concat ! ( - "Alignment of field: " , stringify ! ( i ) , "::" , - stringify ! ( l ) )); - } - impl Clone for i { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(i)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(i)) + ); + assert_eq!( + unsafe { &(*(0 as *const i)).j as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(i), "::", stringify!(j)) + ); + assert_eq!( + unsafe { &(*(0 as *const i)).k as *const _ as usize }, + 8usize, + concat!("Alignment of field: ", stringify!(i), "::", stringify!(k)) + ); + assert_eq!( + unsafe { &(*(0 as *const i)).l as *const _ as usize }, + 16usize, + concat!("Alignment of field: ", stringify!(i), "::", stringify!(l)) + ); } impl Default for i { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Copy, Clone)] pub struct d { pub m: root::i, } #[test] fn bindgen_test_layout_d() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of: " , stringify ! ( d ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( d ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const d ) ) . m as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( d ) , "::" , - stringify ! ( m ) )); - } - impl Clone for d { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(d)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(d)) + ); + assert_eq!( + unsafe { &(*(0 as *const d)).m as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(d), "::", stringify!(m)) + ); } impl Default for d { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -88,17 +98,25 @@ pub mod root { } #[test] fn bindgen_test_layout_F() { - assert_eq!(::std::mem::size_of::() , 264usize , concat ! ( - "Size of: " , stringify ! ( F ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( F ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const F ) ) . w as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( F ) , "::" , - stringify ! ( w ) )); + assert_eq!( + ::std::mem::size_of::(), + 264usize, + concat!("Size of: ", stringify!(F)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(F)) + ); + assert_eq!( + unsafe { &(*(0 as *const F)).w as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(F), "::", stringify!(w)) + ); } impl Default for F { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } } diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 2fcefa123e..928701ef18 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -12,7 +12,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Value { pub _address: u8, } @@ -30,14 +30,9 @@ pub mod root { ); } extern "C" { - #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"] + #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"] pub fn Value_a(this: *mut root::JS::Value, arg1: root::JSWhyMagic); } - impl Clone for Value { - fn clone(&self) -> Self { - *self - } - } impl Value { #[inline] pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) { @@ -46,5 +41,5 @@ pub mod root { } } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum JSWhyMagic { } + pub enum JSWhyMagic {} } diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs index 66e1c04358..11a99ad142 100644 --- a/tests/expectations/tests/issue-447.rs +++ b/tests/expectations/tests/issue-447.rs @@ -15,7 +15,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct GuardObjectNotifier { pub _address: u8, } @@ -32,15 +32,10 @@ pub mod root { concat!("Alignment of ", stringify!(GuardObjectNotifier)) ); } - impl Clone for GuardObjectNotifier { - fn clone(&self) -> Self { - *self - } - } } } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct JSAutoCompartment { pub _address: u8, } @@ -58,17 +53,12 @@ pub mod root { ); } extern "C" { - #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"] + #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"] pub fn JSAutoCompartment_JSAutoCompartment( this: *mut root::JSAutoCompartment, arg1: root::mozilla::detail::GuardObjectNotifier, ); } - impl Clone for JSAutoCompartment { - fn clone(&self) -> Self { - *self - } - } impl JSAutoCompartment { #[inline] pub unsafe fn new(arg1: root::mozilla::detail::GuardObjectNotifier) -> Self { diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 3eae94880a..b2ddf7138c 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -8,7 +8,10 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, ENUM_VARIANT_2 = 1, } +pub enum _bindgen_ty_1 { + ENUM_VARIANT_1 = 0, + ENUM_VARIANT_2 = 1, +} pub type JS_Alias = u8; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -16,32 +19,46 @@ pub struct JS_Base { pub f: JS_Alias, } impl Default for JS_Base { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct JS_AutoIdVector { pub _base: JS_Base, } #[test] fn bindgen_test_layout_JS_AutoIdVector() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( JS_AutoIdVector ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( JS_AutoIdVector ) )); -} -impl Clone for JS_AutoIdVector { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(JS_AutoIdVector)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(JS_AutoIdVector)) + ); } impl Default for JS_AutoIdVector { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( JS_Base ) - )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - JS_Base ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(JS_Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(JS_Base) + ) + ); } diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 50ea61e075..ba2ef976b3 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -10,30 +10,43 @@ pub struct Outer { pub i: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct AutoIdVector { pub ar: Outer, } #[test] fn bindgen_test_layout_AutoIdVector() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( AutoIdVector ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( AutoIdVector ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AutoIdVector ) ) . ar as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( AutoIdVector ) , "::" , - stringify ! ( ar ) )); -} -impl Clone for AutoIdVector { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AutoIdVector)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AutoIdVector)) + ); + assert_eq!( + unsafe { &(*(0 as *const AutoIdVector)).ar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(AutoIdVector), + "::", + stringify!(ar) + ) + ); } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( Outer ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Outer - ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Outer)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Outer)) + ); } diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 0d13c10dca..69a59d5a85 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -10,24 +10,32 @@ pub struct a { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { pub ar: a, } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 1usize , concat ! ( - "Size of: " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 1usize , concat ! ( - "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . ar as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" - , stringify ! ( ar ) )); -} -impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::<_bindgen_ty_1>(), + 1usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::<_bindgen_ty_1>(), + 1usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const _bindgen_ty_1)).ar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(ar) + ) + ); } extern "C" { #[link_name = "\u{1}AutoIdVector"] @@ -35,9 +43,14 @@ extern "C" { } #[test] fn __bindgen_test_layout_a_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( a ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( a ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(a)) + ); } diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 87b38f283f..b6640998d7 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -6,28 +6,33 @@ pub type RefPtr = T; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } pub type A_a = b; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); } #[repr(C)] pub struct e { pub d: RefPtr, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for e { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for e { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -40,17 +45,26 @@ pub struct g { } #[test] fn bindgen_test_layout_g() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( g ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( g ) )); - assert_eq! (unsafe { & ( * ( 0 as * const g ) ) . h as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( g ) , "::" , stringify - ! ( h ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(g)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(g)) + ); + assert_eq!( + unsafe { &(*(0 as *const g)).h as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(g), "::", stringify!(h)) + ); } impl Default for g { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct b { @@ -58,13 +72,21 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( b ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( b ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(b)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(b)) + ); } impl Default for b { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] @@ -72,9 +94,14 @@ extern "C" { } #[test] fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( f ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( f ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(f)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(f)) + ); } diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index e67400cc82..91f76531e8 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -5,77 +5,104 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub bar: Foo_Bar, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { pub abc: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Foo_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Foo_Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Foo_Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Foo_Bar ) ) . abc as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Foo_Bar ) , "::" , - stringify ! ( abc ) )); -} -impl Clone for Foo_Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo_Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo_Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Foo_Bar)).abc as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Foo_Bar), + "::", + stringify!(abc) + ) + ); } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Baz_Bar { pub abc: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Baz_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Baz_Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Baz_Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Baz_Bar ) ) . abc as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Baz_Bar ) , "::" , - stringify ! ( abc ) )); -} -impl Clone for Baz_Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz_Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz_Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Baz_Bar)).abc as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Baz_Bar), + "::", + stringify!(abc) + ) + ); } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); -} -impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)) + ); } diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 82be5c925c..ee5416e09f 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -7,13 +7,15 @@ #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); -impl __IncompleteArrayField { +impl __IncompleteArrayField { #[inline] pub fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) } + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } #[inline] pub unsafe fn as_mut_ptr(&mut self) -> *mut T { ::std::mem::transmute(self) @@ -27,16 +29,18 @@ impl __IncompleteArrayField { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } -impl ::std::fmt::Debug for __IncompleteArrayField { +impl ::std::fmt::Debug for __IncompleteArrayField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__IncompleteArrayField") } } -impl ::std::clone::Clone for __IncompleteArrayField { +impl ::std::clone::Clone for __IncompleteArrayField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __IncompleteArrayField { } +impl ::std::marker::Copy for __IncompleteArrayField {} #[repr(C)] #[derive(Debug)] pub struct rte_ring { @@ -46,60 +50,81 @@ pub struct rte_ring { pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct rte_ring_prod { pub watermark: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_rte_ring_prod() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( rte_ring_prod ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ring_prod ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ring_prod ) ) . watermark as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ring_prod ) , "::" - , stringify ! ( watermark ) )); -} -impl Clone for rte_ring_prod { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_prod)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_prod)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ring_prod)).watermark as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct rte_ring_cons { pub sc_dequeue: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_rte_ring_cons() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( rte_ring_cons ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( rte_ring_cons ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ring_cons ) ) . sc_dequeue as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ring_cons ) , "::" - , stringify ! ( sc_dequeue ) )); -} -impl Clone for rte_ring_cons { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_cons)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_cons)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ring_cons)).sc_dequeue as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); } #[test] fn bindgen_test_layout_rte_ring() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( rte_ring ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( rte_ring ) )); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_ring)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_ring)) + ); } impl Default for rte_ring { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct rte_memzone { pub _address: u8, } -impl Clone for rte_memzone { - fn clone(&self) -> Self { *self } -} diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 11c318a213..a3d594e0ee 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -10,7 +10,7 @@ /// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land /// in rustc). #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct NoDebug { pub c: ::std::os::raw::c_char, pub __bindgen_padding_0: [u8; 63usize], @@ -33,11 +33,6 @@ fn bindgen_test_layout_NoDebug() { ) ); } -impl Clone for NoDebug { - fn clone(&self) -> Self { - *self - } -} impl Default for NoDebug { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -53,7 +48,7 @@ impl ::std::cmp::PartialEq for NoDebug { /// we determine Debug derive-ability before we compute padding, which happens at /// codegen. (Again, we expect to get the alignment wrong for similar reasons.) #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct ShouldDeriveDebugButDoesNot { pub c: [::std::os::raw::c_char; 32usize], pub d: ::std::os::raw::c_char, @@ -87,11 +82,6 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { ) ); } -impl Clone for ShouldDeriveDebugButDoesNot { - fn clone(&self) -> Self { - *self - } -} impl Default for ShouldDeriveDebugButDoesNot { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 31fe3c5396..fc9ebc11e2 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -19,25 +19,31 @@ pub mod root { pub type Maybe_ValueType = T; } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct CapturingContentInfo { pub a: u8, } #[test] fn bindgen_test_layout_CapturingContentInfo() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( - "Size of: " , stringify ! ( CapturingContentInfo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( CapturingContentInfo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const CapturingContentInfo ) ) . a as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - CapturingContentInfo ) , "::" , stringify ! ( a ) )); - } - impl Clone for CapturingContentInfo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(CapturingContentInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(CapturingContentInfo)) + ); + assert_eq!( + unsafe { &(*(0 as *const CapturingContentInfo)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(CapturingContentInfo), + "::", + stringify!(a) + ) + ); } } diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index cfbef26944..07c9cc4a5c 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -19,44 +19,50 @@ pub mod root { pub type Rooted_ElementType = T; } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct c { pub b: u8, } #[test] fn bindgen_test_layout_c() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( c ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( c ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const c ) ) . b as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( c ) , "::" , - stringify ! ( b ) )); - } - impl Clone for c { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(c)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(0 as *const c)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(c), "::", stringify!(b)) + ); } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct B { pub a: root::c, } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( B ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( B ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const B ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( B ) , "::" , - stringify ! ( a ) )); - } - impl Clone for B { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { &(*(0 as *const B)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(B), "::", stringify!(a)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -65,13 +71,21 @@ pub mod root { } #[test] fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( - "Size of template specialization: " , stringify ! ( - root::StaticRefPtr ) )); - assert_eq!(::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of template specialization: " , stringify ! ( - root::StaticRefPtr ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(root::StaticRefPtr) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::StaticRefPtr) + ) + ); } } diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 71f794c387..1750cc0b24 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -15,43 +15,54 @@ pub mod root { } pub type nsRefPtrHashtable_UserDataType = *mut PtrType; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct a { pub b: u8, } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( a ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const a ) ) . b as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , - stringify ! ( b ) )); - } - impl Clone for a { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(a), "::", stringify!(b)) + ); } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct nsCSSValue { pub c: root::a, } #[test] fn bindgen_test_layout_nsCSSValue() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( nsCSSValue ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( nsCSSValue ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsCSSValue ) ) . c as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsCSSValue ) , "::" - , stringify ! ( c ) )); - } - impl Clone for nsCSSValue { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(nsCSSValue)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(nsCSSValue)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsCSSValue)).c as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsCSSValue), + "::", + stringify!(c) + ) + ); } } diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 09f5ee20ee..4878c1fadf 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -7,22 +7,27 @@ #[repr(C)] pub struct VirtualMethods__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct VirtualMethods { pub vtable_: *const VirtualMethods__bindgen_vtable, } #[test] fn bindgen_test_layout_VirtualMethods() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( VirtualMethods ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( VirtualMethods ) )); -} -impl Clone for VirtualMethods { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(VirtualMethods)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(VirtualMethods)) + ); } impl Default for VirtualMethods { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -30,31 +35,38 @@ pub struct Set { pub bar: ::std::os::raw::c_int, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ServoElementSnapshotTable { pub _base: Set, } #[test] fn bindgen_test_layout_ServoElementSnapshotTable() { - assert_eq!(::std::mem::size_of::() , 4usize , - concat ! ( - "Size of: " , stringify ! ( ServoElementSnapshotTable ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( ServoElementSnapshotTable ) - )); -} -impl Clone for ServoElementSnapshotTable { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ServoElementSnapshotTable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ServoElementSnapshotTable)) + ); } impl Default for ServoElementSnapshotTable { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of template specialization: " , stringify ! ( Set ) )); - assert_eq!(::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Set ) - )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of template specialization: ", stringify!(Set)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(Set)) + ); } diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 17e6398138..96963ba553 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -5,18 +5,21 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_1: [u64; 4usize], pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 32usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index b07e17c4b5..3dde6e7302 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -10,40 +10,47 @@ pub struct A { _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct B { pub _bindgen_opaque_blob: u8, } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( B ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( B ) )); -} -impl Clone for B { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)) + ); } extern "C" { #[link_name = "\u{1}_ZN1B1aE"] pub static mut B_a: A; } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct C { pub b: B, } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . b as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( b ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(b)) + ); } diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 1e15360685..0807873b59 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -5,61 +5,76 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Pupper { pub _address: u8, } #[test] fn bindgen_test_layout_Pupper() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Pupper ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Pupper ) )); -} -impl Clone for Pupper { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Pupper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Pupper)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Doggo { pub _address: u8, } #[test] fn bindgen_test_layout_Doggo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Doggo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Doggo ) )); -} -impl Clone for Doggo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Doggo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Doggo)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct SuchWow { pub _address: u8, } #[test] fn bindgen_test_layout_SuchWow() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( SuchWow ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( SuchWow ) )); -} -impl Clone for SuchWow { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(SuchWow)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(SuchWow)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { pub _bindgen_opaque_blob: u8, } #[test] fn bindgen_test_layout_Opaque() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Opaque ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Opaque ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Opaque)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Opaque)) + ); } extern "C" { #[link_name = "\u{1}_ZN6Opaque17eleven_out_of_tenEv"] @@ -69,9 +84,6 @@ extern "C" { #[link_name = "\u{1}_ZN6OpaqueC1E6Pupper"] pub fn Opaque_Opaque(this: *mut Opaque, pup: Pupper); } -impl Clone for Opaque { - fn clone(&self) -> Self { *self } -} impl Opaque { #[inline] pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow { @@ -89,22 +101,30 @@ extern "C" { pub static mut Opaque_MAJESTIC_AF: Doggo; } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Whitelisted { pub some_member: Opaque, } #[test] fn bindgen_test_layout_Whitelisted() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Whitelisted ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Whitelisted ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Whitelisted ) ) . some_member as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Whitelisted ) , "::" , - stringify ! ( some_member ) )); -} -impl Clone for Whitelisted { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Whitelisted)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Whitelisted)) + ); + assert_eq!( + unsafe { &(*(0 as *const Whitelisted)).some_member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Whitelisted), + "::", + stringify!(some_member) + ) + ); } diff --git a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index c894b95c97..36cae7222f 100644 --- a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -5,17 +5,20 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/issue-834.rs b/tests/expectations/tests/issue-834.rs index 1e507ad21f..a8014fb92e 100644 --- a/tests/expectations/tests/issue-834.rs +++ b/tests/expectations/tests/issue-834.rs @@ -5,17 +5,20 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct U { pub _address: u8, } #[test] fn bindgen_test_layout_U() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( U ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( U ) )); -} -impl Clone for U { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(U)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(U)) + ); } diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 9f446d7045..61cbfc3a48 100644 --- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -12,7 +12,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Type { pub _address: u8, } @@ -22,15 +22,18 @@ pub mod root { } #[test] fn bindgen_test_layout_Type() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Type ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Type ) )); - } - impl Clone for Type { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Type)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Type)) + ); } } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum a { } + pub enum a {} } diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs index c5ecb96665..b857537895 100644 --- a/tests/expectations/tests/issue_311.rs +++ b/tests/expectations/tests/issue_311.rs @@ -9,37 +9,39 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct jsval_layout { pub __bindgen_anon_1: root::jsval_layout__bindgen_ty_1, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct jsval_layout__bindgen_ty_1 { pub _address: u8, } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , - 1usize , concat ! ( - "Size of: " , stringify ! ( jsval_layout__bindgen_ty_1 ) - )); - assert_eq! (::std::mem::align_of::() , - 1usize , concat ! ( - "Alignment of " , stringify ! ( jsval_layout__bindgen_ty_1 - ) )); - } - impl Clone for jsval_layout__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) + ); } #[test] fn bindgen_test_layout_jsval_layout() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( jsval_layout ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( jsval_layout ) )); - } - impl Clone for jsval_layout { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(jsval_layout)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(jsval_layout)) + ); } } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index c8e01a0c61..a422ffc052 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -72,7 +72,7 @@ pub enum JSWhyMagic { JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union jsval_layout { pub asBits: u64, pub debugView: jsval_layout__bindgen_ty_1, @@ -84,7 +84,7 @@ pub union jsval_layout { _bindgen_union_align: u64, } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_1: u64, pub __bindgen_align: [u64; 0usize], @@ -102,11 +102,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) ); } -impl Clone for jsval_layout__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for jsval_layout__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -192,12 +187,12 @@ impl jsval_layout__bindgen_ty_1 { } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct jsval_layout__bindgen_ty_2 { pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: i32, pub u32: u32, @@ -259,11 +254,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); } -impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -292,11 +282,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { ) ); } -impl Clone for jsval_layout__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -385,18 +370,13 @@ fn bindgen_test_layout_jsval_layout() { ) ); } -impl Clone for jsval_layout { - fn clone(&self) -> Self { - *self - } -} impl Default for jsval_layout { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Value { pub data: jsval_layout, } @@ -423,11 +403,6 @@ fn bindgen_test_layout_Value() { ) ); } -impl Clone for Value { - fn clone(&self) -> Self { - *self - } -} impl Default for Value { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 9d883e3792..859416d76f 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -75,7 +75,7 @@ impl Default for rte_kni_fifo { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct rte_eth_link { /// < ETH_SPEED_NUM_ pub link_speed: u32, @@ -106,11 +106,6 @@ fn bindgen_test_layout_rte_eth_link() { ) ); } -impl Clone for rte_eth_link { - fn clone(&self) -> Self { - *self - } -} impl rte_eth_link { #[inline] pub fn link_duplex(&self) -> u16 { diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index 8f8530686e..d49a870b55 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -22,29 +22,37 @@ pub const ARP_OP_INVREPLY: ::std::os::raw::c_uint = 9; /// administrator and does not contain OUIs. /// See http://standards.ieee.org/regauth/groupmac/tutorial.html #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct ether_addr { /// < Addr bytes in tx order pub addr_bytes: [u8; 6usize], } #[test] fn bindgen_test_layout_ether_addr() { - assert_eq!(::std::mem::size_of::() , 6usize , concat ! ( - "Size of: " , stringify ! ( ether_addr ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( ether_addr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ether_addr ) ) . addr_bytes as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ether_addr ) , "::" , - stringify ! ( addr_bytes ) )); -} -impl Clone for ether_addr { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 6usize, + concat!("Size of: ", stringify!(ether_addr)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ether_addr)) + ); + assert_eq!( + unsafe { &(*(0 as *const ether_addr)).addr_bytes as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ether_addr), + "::", + stringify!(addr_bytes) + ) + ); } /// ARP header IPv4 payload. #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct arp_ipv4 { /// < sender hardware address pub arp_sha: ether_addr, @@ -57,37 +65,60 @@ pub struct arp_ipv4 { } #[test] fn bindgen_test_layout_arp_ipv4() { - assert_eq!(::std::mem::size_of::() , 20usize , concat ! ( - "Size of: " , stringify ! ( arp_ipv4 ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( arp_ipv4 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_ipv4 ) ) . arp_sha as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , - stringify ! ( arp_sha ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_ipv4 ) ) . arp_sip as * const _ as - usize } , 6usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , - stringify ! ( arp_sip ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_ipv4 ) ) . arp_tha as * const _ as - usize } , 10usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , - stringify ! ( arp_tha ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_ipv4 ) ) . arp_tip as * const _ as - usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , - stringify ! ( arp_tip ) )); -} -impl Clone for arp_ipv4 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 20usize, + concat!("Size of: ", stringify!(arp_ipv4)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(arp_ipv4)) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_ipv4)).arp_sha as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sha) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_ipv4)).arp_sip as *const _ as usize }, + 6usize, + concat!( + "Alignment of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sip) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_ipv4)).arp_tha as *const _ as usize }, + 10usize, + concat!( + "Alignment of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tha) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_ipv4)).arp_tip as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tip) + ) + ); } /// ARP header. #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct arp_hdr { pub arp_hrd: u16, pub arp_pro: u16, @@ -98,41 +129,74 @@ pub struct arp_hdr { } #[test] fn bindgen_test_layout_arp_hdr() { - assert_eq!(::std::mem::size_of::() , 28usize , concat ! ( - "Size of: " , stringify ! ( arp_hdr ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( arp_hdr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_hrd as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_hrd ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_pro as * const _ as - usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_pro ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_hln as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_hln ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_pln as * const _ as - usize } , 5usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_pln ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_op as * const _ as - usize } , 6usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_op ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const arp_hdr ) ) . arp_data as * const _ as - usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , - stringify ! ( arp_data ) )); -} -impl Clone for arp_hdr { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 28usize, + concat!("Size of: ", stringify!(arp_hdr)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(arp_hdr)) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_hrd as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hrd) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_pro as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pro) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_hln as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hln) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_pln as *const _ as usize }, + 5usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pln) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_op as *const _ as usize }, + 6usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_op) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const arp_hdr)).arp_data as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_data) + ) + ); } diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index c1a1518799..7dcd507a5b 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -49,7 +49,7 @@ pub type rte_mempool_get_count = ::std::option::Option< >; /// Structure defining mempool operations structure #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_mempool_ops { /// < Name of mempool ops struct. pub name: [::std::os::raw::c_char; 32usize], @@ -133,11 +133,6 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); } -impl Clone for rte_mempool_ops { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mempool_ops { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -152,7 +147,7 @@ impl ::std::cmp::PartialEq for rte_mempool_ops { } /// The rte_spinlock_t type. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_spinlock_t { /// < lock status 0 = unlocked, 1 = locked pub locked: ::std::os::raw::c_int, @@ -180,11 +175,6 @@ fn bindgen_test_layout_rte_spinlock_t() { ) ); } -impl Clone for rte_spinlock_t { - fn clone(&self) -> Self { - *self - } -} /// Structure storing the table of registered ops structs, each of which contain /// the function pointers for the mempool ops functions. /// Each process has its own storage for this ops struct array so that @@ -193,7 +183,7 @@ impl Clone for rte_spinlock_t { /// any function pointers stored directly in the mempool struct would not be. /// This results in us simply having "ops_index" in the mempool struct. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_mempool_ops_table { /// < Spinlock for add/delete. pub sl: rte_spinlock_t, @@ -241,11 +231,6 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ) ); } -impl Clone for rte_mempool_ops_table { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mempool_ops_table { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -253,7 +238,7 @@ impl Default for rte_mempool_ops_table { } /// Structure to hold malloc heap #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct malloc_heap { pub lock: rte_spinlock_t, pub free_head: [malloc_heap__bindgen_ty_1; 13usize], @@ -261,7 +246,7 @@ pub struct malloc_heap { pub total_size: usize, } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct malloc_heap__bindgen_ty_1 { pub lh_first: *mut malloc_elem, } @@ -288,11 +273,6 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { ) ); } -impl Clone for malloc_heap__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for malloc_heap__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -346,11 +326,6 @@ fn bindgen_test_layout_malloc_heap() { ) ); } -impl Clone for malloc_heap { - fn clone(&self) -> Self { - *self - } -} impl Default for malloc_heap { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -363,12 +338,7 @@ impl ::std::cmp::PartialEq for malloc_heap { } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct malloc_elem { pub _address: u8, } -impl Clone for malloc_elem { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 6cfd85a483..6c8ec85083 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -20,7 +20,7 @@ pub enum _bindgen_ty_1 { } /// @internal fragmented mbuf #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag { /// < offset into the packet pub ofs: u16, @@ -72,11 +72,6 @@ fn bindgen_test_layout_ip_frag() { ) ); } -impl Clone for ip_frag { - fn clone(&self) -> Self { - *self - } -} impl Default for ip_frag { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -84,7 +79,7 @@ impl Default for ip_frag { } /// @internal to uniquely indetify fragmented datagram. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag_key { /// < src address, first 8 bytes used for IPv4 pub src_dst: [u64; 4usize], @@ -136,15 +131,10 @@ fn bindgen_test_layout_ip_frag_key() { ) ); } -impl Clone for ip_frag_key { - fn clone(&self) -> Self { - *self - } -} /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct ip_frag_pkt { /// < LRU list pub lru: ip_frag_pkt__bindgen_ty_1, @@ -163,7 +153,7 @@ pub struct ip_frag_pkt { pub __bindgen_padding_0: [u64; 6usize], } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag_pkt__bindgen_ty_1 { pub tqe_next: *mut ip_frag_pkt, pub tqe_prev: *mut *mut ip_frag_pkt, @@ -201,11 +191,6 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ) ); } -impl Clone for ip_frag_pkt__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -289,11 +274,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); } -impl Clone for ip_frag_pkt { - fn clone(&self) -> Self { - *self - } -} impl Default for ip_frag_pkt { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -301,19 +281,14 @@ impl Default for ip_frag_pkt { } impl ::std::cmp::PartialEq for ip_frag_pkt { fn eq(&self, other: &ip_frag_pkt) -> bool { - self.lru == other.lru && self.key == other.key && self.start == other.start && - self.total_size == other.total_size && self.frag_size == other.frag_size && - self.last_idx == other.last_idx && self.frags == other.frags + self.lru == other.lru && self.key == other.key && self.start == other.start + && self.total_size == other.total_size && self.frag_size == other.frag_size + && self.last_idx == other.last_idx && self.frags == other.frags } } /// < fragment mbuf #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf { pub _address: u8, } -impl Clone for rte_mbuf { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index be8414325e..ca4147f013 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -8,7 +8,7 @@ /// Stores a pointer to the ops struct, and the offset: the place to /// write the parsed result in the destination structure. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct cmdline_token_hdr { pub ops: *mut cmdline_token_ops, pub offset: ::std::os::raw::c_uint, @@ -46,11 +46,6 @@ fn bindgen_test_layout_cmdline_token_hdr() { ) ); } -impl Clone for cmdline_token_hdr { - fn clone(&self) -> Self { - *self - } -} impl Default for cmdline_token_hdr { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -75,7 +70,7 @@ pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; /// get_help() fills the dstbuf with the help for the token. It returns /// -1 on error and 0 on success. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct cmdline_token_ops { /// parse(token ptr, buf, res pts, buf len) pub parse: ::std::option::Option< @@ -162,11 +157,6 @@ fn bindgen_test_layout_cmdline_token_ops() { ) ); } -impl Clone for cmdline_token_ops { - fn clone(&self) -> Self { - *self - } -} impl Default for cmdline_token_ops { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -185,7 +175,7 @@ pub enum cmdline_numtype { INT64 = 7, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct cmdline_token_num_data { pub type_: cmdline_numtype, } @@ -212,18 +202,13 @@ fn bindgen_test_layout_cmdline_token_num_data() { ) ); } -impl Clone for cmdline_token_num_data { - fn clone(&self) -> Self { - *self - } -} impl Default for cmdline_token_num_data { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct cmdline_token_num { pub hdr: cmdline_token_hdr, pub num_data: cmdline_token_num_data, @@ -261,11 +246,6 @@ fn bindgen_test_layout_cmdline_token_num() { ) ); } -impl Clone for cmdline_token_num { - fn clone(&self) -> Self { - *self - } -} impl Default for cmdline_token_num { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 5e17ec2a79..d5f1f1a540 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -52,7 +52,7 @@ pub enum rte_eth_rx_mq_mode { } /// A structure used to configure the RX features of an Ethernet port. #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rxmode { /// The multi-queue packet distribution mode to be used, e.g. RSS. pub mq_mode: rte_eth_rx_mq_mode, @@ -105,11 +105,6 @@ fn bindgen_test_layout_rte_eth_rxmode() { ) ); } -impl Clone for rte_eth_rxmode { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_rxmode { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -475,7 +470,7 @@ pub enum rte_eth_tx_mq_mode { } /// A structure used to configure the TX features of an Ethernet port. #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_txmode { /// < TX multi-queues mode. pub mq_mode: rte_eth_tx_mq_mode, @@ -516,11 +511,6 @@ fn bindgen_test_layout_rte_eth_txmode() { ) ); } -impl Clone for rte_eth_txmode { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_txmode { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -662,7 +652,7 @@ impl rte_eth_txmode { /// types of IPv4/IPv6 packets to which the RSS hashing must be applied. /// Supplying an *rss_hf* equal to zero disables the RSS feature. #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { /// < If not NULL, 40-byte hash key. pub rss_key: *mut u8, @@ -714,11 +704,6 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); } -impl Clone for rte_eth_rss_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_rss_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -752,7 +737,7 @@ pub enum rte_eth_nb_pools { /// A default pool may be used, if desired, to route all traffic which /// does not match the vlan filter rules. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_eth_vmdq_dcb_conf { /// < With DCB, 16 or 32 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -767,7 +752,7 @@ pub struct rte_eth_vmdq_dcb_conf { pub dcb_tc: [u8; 8usize], } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { /// < The vlan id of the received frame pub vlan_id: u16, @@ -812,11 +797,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); } -impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { assert_eq!( @@ -890,18 +870,13 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); } -impl Clone for rte_eth_vmdq_dcb_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_rx_conf { /// < Possible DCB TCs, 4 or 8 TCs pub nb_tcs: rte_eth_nb_tcs, @@ -941,18 +916,13 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ) ); } -impl Clone for rte_eth_dcb_rx_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_tx_conf { /// < With DCB, 16 or 32 pools. pub nb_queue_pools: rte_eth_nb_pools, @@ -992,18 +962,13 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ) ); } -impl Clone for rte_eth_vmdq_dcb_tx_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_tx_conf { /// < Possible DCB TCs, 4 or 8 TCs. pub nb_tcs: rte_eth_nb_tcs, @@ -1043,18 +1008,13 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ) ); } -impl Clone for rte_eth_dcb_tx_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_tx_conf { /// < VMDq mode, 64 pools. pub nb_queue_pools: rte_eth_nb_pools, @@ -1082,18 +1042,13 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { ) ); } -impl Clone for rte_eth_vmdq_tx_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_eth_vmdq_rx_conf { /// < VMDq only mode, 8 or 64 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -1111,7 +1066,7 @@ pub struct rte_eth_vmdq_rx_conf { pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { /// < The vlan id of the received frame pub vlan_id: u16, @@ -1156,11 +1111,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); } -impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { assert_eq!( @@ -1244,11 +1194,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); } -impl Clone for rte_eth_vmdq_rx_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -1283,7 +1228,7 @@ pub enum rte_fdir_status_mode { } /// A structure used to define the input for IPV4 flow #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_ipv4_flow { /// < IPv4 source address in big endian. pub src_ip: u32, @@ -1359,14 +1304,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); } -impl Clone for rte_eth_ipv4_flow { - fn clone(&self) -> Self { - *self - } -} /// A structure used to define the input for IPV6 flow #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_ipv6_flow { /// < IPv6 source address in big endian. pub src_ip: [u32; 4usize], @@ -1442,15 +1382,10 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); } -impl Clone for rte_eth_ipv6_flow { - fn clone(&self) -> Self { - *self - } -} /// A structure used to configure FDIR masks that are used by the device /// to match the various fields of RX packet headers. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { /// < Bit mask for vlan_tci in big endian pub vlan_tci_mask: u16, @@ -1564,11 +1499,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); } -impl Clone for rte_eth_fdir_masks { - fn clone(&self) -> Self { - *self - } -} #[repr(u32)] /// Payload type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1583,7 +1513,7 @@ pub enum rte_eth_payload_type { /// A structure used to select bytes extracted from the protocol layers to /// flexible payload for filter #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { /// < Payload type pub type_: rte_eth_payload_type, @@ -1622,11 +1552,6 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ) ); } -impl Clone for rte_eth_flex_payload_cfg { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -1635,7 +1560,7 @@ impl Default for rte_eth_flex_payload_cfg { /// A structure used to define FDIR masks for flexible payload /// for each flow type #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { pub flow_type: u16, pub mask: [u8; 16usize], @@ -1673,15 +1598,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); } -impl Clone for rte_eth_fdir_flex_mask { - fn clone(&self) -> Self { - *self - } -} /// A structure used to define all flexible payload related setting /// include flex payload and flex mask #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { /// < The number of following payload cfg pub nb_payloads: u16, @@ -1743,11 +1663,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); } -impl Clone for rte_eth_fdir_flex_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -1758,7 +1673,7 @@ impl Default for rte_eth_fdir_flex_conf { /// /// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { /// < Flow Director mode. pub mode: rte_fdir_mode, @@ -1844,11 +1759,6 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); } -impl Clone for rte_fdir_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_fdir_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -1856,7 +1766,7 @@ impl Default for rte_fdir_conf { } /// A structure used to enable/disable specific device interrupts. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_intr_conf { /// enable/disable lsc interrupt. 0 (default) - disable, 1 enable pub lsc: u16, @@ -1896,16 +1806,11 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); } -impl Clone for rte_intr_conf { - fn clone(&self) -> Self { - *self - } -} /// A structure used to configure an Ethernet port. /// Depending upon the RX multi-queue mode, extra advanced /// configuration settings may be needed. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_eth_conf { /// < bitmap of ETH_LINK_SPEED_XXX of speeds to be /// used. ETH_LINK_SPEED_FIXED disables link @@ -1938,7 +1843,7 @@ pub struct rte_eth_conf { pub intr_conf: rte_intr_conf, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_eth_conf__bindgen_ty_1 { /// < Port RSS configuration pub rss_conf: rte_eth_rss_conf, @@ -1999,18 +1904,13 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); } -impl Clone for rte_eth_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: rte_eth_vmdq_dcb_tx_conf, pub dcb_tx_conf: rte_eth_dcb_tx_conf, @@ -2062,11 +1962,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ) ); } -impl Clone for rte_eth_conf__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -2175,11 +2070,6 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); } -impl Clone for rte_eth_conf { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_eth_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index 72552bea93..e848c52e06 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -7,7 +7,7 @@ pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64; pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_kni_mbuf { pub buf_addr: *mut ::std::os::raw::c_void, pub buf_physaddr: u64, @@ -33,82 +33,154 @@ pub struct rte_kni_mbuf { } #[test] fn bindgen_test_layout_rte_kni_mbuf() { - assert_eq!(::std::mem::size_of::() , 128usize , concat ! ( - "Size of: " , stringify ! ( rte_kni_mbuf ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_addr as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( buf_addr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_physaddr as * - const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( buf_physaddr ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pad0 as * const _ as - usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pad0 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . data_off as * const _ - as usize } , 18usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( data_off ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pad1 as * const _ as - usize } , 20usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pad1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . nb_segs as * const _ - as usize } , 22usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( nb_segs ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pad4 as * const _ as - usize } , 23usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pad4 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . ol_flags as * const _ - as usize } , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( ol_flags ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pad2 as * const _ as - usize } , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pad2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pkt_len as * const _ - as usize } , 36usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pkt_len ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . data_len as * const _ - as usize } , 40usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( data_len ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pad3 as * const _ as - usize } , 64usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pad3 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . pool as * const _ as - usize } , 72usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( pool ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_kni_mbuf ) ) . next as * const _ as - usize } , 80usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , - stringify ! ( next ) )); -} -impl Clone for rte_kni_mbuf { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_kni_mbuf)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).buf_addr as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_addr) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).buf_physaddr as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pad0 as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad0) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).data_off as *const _ as usize }, + 18usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_off) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pad1 as *const _ as usize }, + 20usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).nb_segs as *const _ as usize }, + 22usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(nb_segs) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pad4 as *const _ as usize }, + 23usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad4) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).ol_flags as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(ol_flags) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pad2 as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad2) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pkt_len as *const _ as usize }, + 36usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pkt_len) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).data_len as *const _ as usize }, + 40usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_len) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pad3 as *const _ as usize }, + 64usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad3) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).pool as *const _ as usize }, + 72usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pool) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_kni_mbuf)).next as *const _ as usize }, + 80usize, + concat!( + "Alignment of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(next) + ) + ); } impl Default for rte_kni_mbuf { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 0d86acda61..24034d9270 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -7,13 +7,15 @@ #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); -impl __IncompleteArrayField { +impl __IncompleteArrayField { #[inline] pub fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) } + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } #[inline] pub unsafe fn as_mut_ptr(&mut self) -> *mut T { ::std::mem::transmute(self) @@ -27,16 +29,18 @@ impl __IncompleteArrayField { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } -impl ::std::fmt::Debug for __IncompleteArrayField { +impl ::std::fmt::Debug for __IncompleteArrayField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__IncompleteArrayField") } } -impl ::std::clone::Clone for __IncompleteArrayField { +impl ::std::clone::Clone for __IncompleteArrayField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __IncompleteArrayField { } +impl ::std::marker::Copy for __IncompleteArrayField {} pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; pub const RTE_LIBRTE_IP_FRAG_MAX_FRAG: ::std::os::raw::c_uint = 4; pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX; @@ -53,7 +57,7 @@ pub enum _bindgen_ty_1 { } /// @internal fragmented mbuf #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ip_frag { /// < offset into the packet pub ofs: u16, @@ -64,35 +68,55 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( ip_frag ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( ip_frag ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag ) ) . ofs as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag ) , "::" , - stringify ! ( ofs ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag ) ) . len as * const _ as usize } - , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag ) , "::" , - stringify ! ( len ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag ) ) . mb as * const _ as usize } - , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag ) , "::" , - stringify ! ( mb ) )); -} -impl Clone for ip_frag { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag)).ofs as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag), + "::", + stringify!(ofs) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag)).len as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag)).mb as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag), + "::", + stringify!(mb) + ) + ); } impl Default for ip_frag { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } /// @internal to uniquely indetify fragmented datagram. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct ip_frag_key { /// < src address, first 8 bytes used for IPv4 pub src_dst: [u64; 4usize], @@ -103,33 +127,51 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { - assert_eq!(::std::mem::size_of::() , 40usize , concat ! ( - "Size of: " , stringify ! ( ip_frag_key ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( ip_frag_key ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_key ) ) . src_dst as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" , - stringify ! ( src_dst ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_key ) ) . id as * const _ as - usize } , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" , - stringify ! ( id ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_key ) ) . key_len as * const _ as - usize } , 36usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" , - stringify ! ( key_len ) )); -} -impl Clone for ip_frag_key { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(ip_frag_key)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_key)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_key)).src_dst as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_key), + "::", + stringify!(src_dst) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_key)).id as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_key), + "::", + stringify!(id) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_key)).key_len as *const _ as usize }, + 36usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_key), + "::", + stringify!(key_len) + ) + ); } /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct ip_frag_pkt { /// < LRU list pub lru: ip_frag_pkt__bindgen_ty_1, @@ -148,117 +190,179 @@ pub struct ip_frag_pkt { pub __bindgen_padding_0: [u64; 6usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ip_frag_pkt__bindgen_ty_1 { pub tqe_next: *mut ip_frag_pkt, pub tqe_prev: *mut *mut ip_frag_pkt, } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 16usize , - concat ! ( - "Size of: " , stringify ! ( ip_frag_pkt__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 8usize , - concat ! ( - "Alignment of " , stringify ! ( ip_frag_pkt__bindgen_ty_1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_next - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_next ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_prev - as * const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( - ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_prev ) - )); -} -impl Clone for ip_frag_pkt__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_next as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_prev as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev) + ) + ); } impl Default for ip_frag_pkt__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_ip_frag_pkt() { - assert_eq!(::std::mem::size_of::() , 192usize , concat ! ( - "Size of: " , stringify ! ( ip_frag_pkt ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . lru as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( lru ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . key as * const _ as - usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( key ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . start as * const _ as - usize } , 56usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( start ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . total_size as * const _ - as usize } , 64usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( total_size ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . frag_size as * const _ - as usize } , 68usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( frag_size ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . last_idx as * const _ - as usize } , 72usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( last_idx ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_pkt ) ) . frags as * const _ as - usize } , 80usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" , - stringify ! ( frags ) )); -} -impl Clone for ip_frag_pkt { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 192usize, + concat!("Size of: ", stringify!(ip_frag_pkt)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).lru as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(lru) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).key as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(key) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).start as *const _ as usize }, + 56usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(start) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).total_size as *const _ as usize }, + 64usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).frag_size as *const _ as usize }, + 68usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).last_idx as *const _ as usize }, + 72usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(last_idx) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_pkt)).frags as *const _ as usize }, + 80usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frags) + ) + ); } impl Default for ip_frag_pkt { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ip_pkt_list { pub tqh_first: *mut ip_frag_pkt, pub tqh_last: *mut *mut ip_frag_pkt, } #[test] fn bindgen_test_layout_ip_pkt_list() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( ip_pkt_list ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( ip_pkt_list ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_pkt_list ) ) . tqh_first as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_pkt_list ) , "::" , - stringify ! ( tqh_first ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_pkt_list ) ) . tqh_last as * const _ - as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_pkt_list ) , "::" , - stringify ! ( tqh_last ) )); -} -impl Clone for ip_pkt_list { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_pkt_list)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_pkt_list)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_pkt_list)).tqh_first as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_first) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_pkt_list)).tqh_last as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_last) + ) + ); } impl Default for ip_pkt_list { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } /// fragmentation table statistics #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct ip_frag_tbl_stat { /// < total # of find/insert attempts. pub find_num: u64, @@ -276,44 +380,76 @@ pub struct ip_frag_tbl_stat { } #[test] fn bindgen_test_layout_ip_frag_tbl_stat() { - assert_eq!(::std::mem::size_of::() , 64usize , concat ! - ( "Size of: " , stringify ! ( ip_frag_tbl_stat ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . find_num as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( find_num ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . add_num as * const - _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( add_num ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . del_num as * const - _ as usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( del_num ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . reuse_num as * - const _ as usize } , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( reuse_num ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . fail_total as * - const _ as usize } , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( fail_total ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ip_frag_tbl_stat ) ) . fail_nospace as * - const _ as usize } , 40usize , concat ! ( - "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) , - "::" , stringify ! ( fail_nospace ) )); -} -impl Clone for ip_frag_tbl_stat { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(ip_frag_tbl_stat)) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).find_num as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(find_num) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).add_num as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(add_num) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).del_num as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(del_num) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).reuse_num as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(reuse_num) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).fail_total as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_total) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ip_frag_tbl_stat)).fail_nospace as *const _ as usize }, + 40usize, + concat!( + "Alignment of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_nospace) + ) + ); } impl Default for ip_frag_tbl_stat { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } /// fragmentation table #[repr(C)] @@ -344,73 +480,130 @@ pub struct rte_ip_frag_tbl { } #[test] fn bindgen_test_layout_rte_ip_frag_tbl() { - assert_eq!(::std::mem::size_of::() , 128usize , concat ! - ( "Size of: " , stringify ! ( rte_ip_frag_tbl ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . max_cycles as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( max_cycles ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . entry_mask as * - const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( entry_mask ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . max_entries as * - const _ as usize } , 12usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( max_entries ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . use_entries as * - const _ as usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( use_entries ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . bucket_entries as * - const _ as usize } , 20usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( bucket_entries ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . nb_entries as * - const _ as usize } , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( nb_entries ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . nb_buckets as * - const _ as usize } , 28usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( nb_buckets ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . last as * const _ - as usize } , 32usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( last ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . lru as * const _ as - usize } , 40usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( lru ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . stat as * const _ - as usize } , 64usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( stat ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const rte_ip_frag_tbl ) ) . pkt as * const _ as - usize } , 128usize , concat ! ( - "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , - "::" , stringify ! ( pkt ) )); + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_ip_frag_tbl)) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).max_cycles as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_cycles) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).entry_mask as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(entry_mask) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).max_entries as *const _ as usize }, + 12usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_entries) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).use_entries as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(use_entries) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).bucket_entries as *const _ as usize }, + 20usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(bucket_entries) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).nb_entries as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_entries) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).nb_buckets as *const _ as usize }, + 28usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_buckets) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).last as *const _ as usize }, + 32usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(last) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).lru as *const _ as usize }, + 40usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(lru) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).stat as *const _ as usize }, + 64usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(stat) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const rte_ip_frag_tbl)).pkt as *const _ as usize }, + 128usize, + concat!( + "Alignment of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(pkt) + ) + ); } impl Default for rte_ip_frag_tbl { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } /// < fragment mbuf #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct rte_mbuf { pub _address: u8, } -impl Clone for rte_mbuf { - fn clone(&self) -> Self { *self } -} diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 90a367c6c7..1db17172dc 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -12,7 +12,7 @@ pub type MARKER8 = [u8; 0usize]; pub type MARKER64 = [u64; 0usize]; /// The atomic counter structure. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_atomic16_t { /// < An internal counter value. pub cnt: i16, @@ -40,11 +40,6 @@ fn bindgen_test_layout_rte_atomic16_t() { ) ); } -impl Clone for rte_atomic16_t { - fn clone(&self) -> Self { - *self - } -} /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] pub struct rte_mbuf { @@ -99,7 +94,7 @@ pub struct rte_mbuf { /// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC /// config option. #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { /// < Atomically accessed refcnt pub refcnt_atomic: rte_atomic16_t, @@ -140,18 +135,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_2 { /// < L2/L3/L4 and tunnel information. pub packet_type: u32, @@ -159,7 +149,7 @@ pub union rte_mbuf__bindgen_ty_2 { _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_1: [u8; 4usize], pub __bindgen_align: [u32; 0usize], @@ -183,11 +173,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { @@ -483,18 +468,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3 { /// < RSS hash result if RSS enabled pub rss: u32, @@ -507,20 +487,20 @@ pub union rte_mbuf__bindgen_ty_3 { _bindgen_union_align: [u32; 2usize], } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, pub hi: u32, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, pub lo: u32, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, @@ -570,11 +550,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) ); } -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { assert_eq!( @@ -607,11 +582,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -646,18 +616,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, @@ -701,11 +666,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { assert_eq!( @@ -759,18 +719,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_3 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_4 { /// < Can be used for external metadata pub userdata: *mut ::std::os::raw::c_void, @@ -811,18 +766,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_4 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_5 { /// < combined for easy fetch pub tx_offload: u64, @@ -830,7 +780,7 @@ pub union rte_mbuf__bindgen_ty_5 { _bindgen_union_align: u64, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_1: [u16; 4usize], pub __bindgen_align: [u64; 0usize], @@ -854,11 +804,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { @@ -1116,11 +1061,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { ) ); } -impl Clone for rte_mbuf__bindgen_ty_5 { - fn clone(&self) -> Self { - *self - } -} impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -1351,12 +1291,7 @@ impl Default for rte_mbuf { } /// < Pool from which mbuf was allocated. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mempool { pub _address: u8, } -impl Clone for rte_mempool { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs index b86a5c9e07..8db72d0fa8 100644 --- a/tests/expectations/tests/libclang-3.8/auto.rs +++ b/tests/expectations/tests/libclang-3.8/auto.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -26,11 +26,6 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs index 6bbffa1ace..b7d5128303 100644 --- a/tests/expectations/tests/libclang-3.8/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.8/call-conv-field.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) @@ -46,11 +46,6 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); } -impl Clone for JNINativeInterface_ { - fn clone(&self) -> Self { - *self - } -} impl Default for JNINativeInterface_ { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs index 1f5fcf6398..356368426b 100644 --- a/tests/expectations/tests/libclang-3.8/const_bool.rs +++ b/tests/expectations/tests/libclang-3.8/const_bool.rs @@ -9,7 +9,7 @@ extern "C" { pub static mut k: bool; } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } @@ -30,11 +30,6 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); } -impl Clone for A { - fn clone(&self) -> Self { - *self - } -} pub type foo = bool; extern "C" { #[link_name = "\u{1}_ZL2k2"] diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs index 960b5522f9..797d5f45ed 100644 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs @@ -15,7 +15,7 @@ pub struct Derived { pub b: bool, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Usage { pub _address: u8, } @@ -40,11 +40,6 @@ extern "C" { #[link_name = "\u{1}_ZN5UsageC1Ev"] pub fn Usage_Usage(this: *mut Usage); } -impl Clone for Usage { - fn clone(&self) -> Self { - *self - } -} impl Usage { #[inline] pub unsafe fn new() -> Self { diff --git a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs index 590f491ab1..7b13bb7c33 100644 --- a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Rooted { pub ptr: ::std::os::raw::c_int, } @@ -32,10 +32,5 @@ fn bindgen_test_layout_Rooted() { ) ); } -impl Clone for Rooted { - fn clone(&self) -> Self { - *self - } -} ///
pub type MaybeWrapped
= a; diff --git a/tests/expectations/tests/libclang-3.9/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs index 50acff2e93..2d7dfa3a85 100644 --- a/tests/expectations/tests/libclang-3.9/auto.rs +++ b/tests/expectations/tests/libclang-3.9/auto.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -23,11 +23,6 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs index 8896946e1f..a3c6fe6214 100644 --- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) @@ -46,11 +46,6 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); } -impl Clone for JNINativeInterface_ { - fn clone(&self) -> Self { - *self - } -} impl Default for JNINativeInterface_ { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/libclang-3.9/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs index 7106e0ab8d..14f5139400 100644 --- a/tests/expectations/tests/libclang-3.9/const_bool.rs +++ b/tests/expectations/tests/libclang-3.9/const_bool.rs @@ -6,7 +6,7 @@ pub const k: bool = true; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } @@ -24,10 +24,5 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); } -impl Clone for A { - fn clone(&self) -> Self { - *self - } -} pub type foo = bool; pub const k2: foo = true; diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs index 416711ad4a..97d2eabe41 100644 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs @@ -15,7 +15,7 @@ pub struct Derived { pub b: bool, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Usage { pub _address: u8, } @@ -36,8 +36,3 @@ fn bindgen_test_layout_Usage() { concat!("Alignment of ", stringify!(Usage)) ); } -impl Clone for Usage { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs index 590f491ab1..7b13bb7c33 100644 --- a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Rooted { pub ptr: ::std::os::raw::c_int, } @@ -32,10 +32,5 @@ fn bindgen_test_layout_Rooted() { ) ); } -impl Clone for Rooted { - fn clone(&self) -> Self { - *self - } -} ///
pub type MaybeWrapped
= a; diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs index 1575d05129..2d7dfa3a85 100644 --- a/tests/expectations/tests/libclang-4/auto.rs +++ b/tests/expectations/tests/libclang-4/auto.rs @@ -5,20 +5,23 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs index 648560cf56..a3c6fe6214 100644 --- a/tests/expectations/tests/libclang-4/call-conv-field.rs +++ b/tests/expectations/tests/libclang-4/call-conv-field.rs @@ -5,36 +5,51 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option ::std::os::raw::c_int>, + pub GetVersion: ::std::option::Option< + unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) + -> ::std::os::raw::c_int, + >, pub __hack: ::std::os::raw::c_ulonglong, } #[test] fn bindgen_test_layout_JNINativeInterface_() { - assert_eq!(::std::mem::size_of::() , 16usize , concat - ! ( "Size of: " , stringify ! ( JNINativeInterface_ ) )); - assert_eq! (::std::mem::align_of::() , 8usize , - concat ! ( - "Alignment of " , stringify ! ( JNINativeInterface_ ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const JNINativeInterface_ ) ) . GetVersion as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( JNINativeInterface_ ) , - "::" , stringify ! ( GetVersion ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const JNINativeInterface_ ) ) . __hack as * - const _ as usize } , 8usize , concat ! ( - "Alignment of field: " , stringify ! ( JNINativeInterface_ ) , - "::" , stringify ! ( __hack ) )); -} -impl Clone for JNINativeInterface_ { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(JNINativeInterface_)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(JNINativeInterface_)) + ); + assert_eq!( + unsafe { &(*(0 as *const JNINativeInterface_)).GetVersion as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const JNINativeInterface_)).__hack as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack) + ) + ); } impl Default for JNINativeInterface_ { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "stdcall" { #[link_name = "\u{1}_bar@0"] diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs index fd0273aa70..14f5139400 100644 --- a/tests/expectations/tests/libclang-4/const_bool.rs +++ b/tests/expectations/tests/libclang-4/const_bool.rs @@ -6,20 +6,23 @@ pub const k: bool = true; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); } pub type foo = bool; pub const k2: foo = true; diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs index 1cb28c1429..97d2eabe41 100644 --- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs @@ -15,7 +15,7 @@ pub struct Derived { pub b: bool, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Usage { pub _address: u8, } @@ -25,11 +25,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Usage() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Usage ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Usage ) )); -} -impl Clone for Usage { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Usage)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Usage)) + ); } diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs index b8d4fbecf1..e0b8616d89 100644 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Rooted { pub ptr: MaybeWrapped<::std::os::raw::c_int>, } @@ -32,11 +32,6 @@ fn bindgen_test_layout_Rooted() { ) ); } -impl Clone for Rooted { - fn clone(&self) -> Self { - *self - } -} impl Default for Rooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -51,8 +46,15 @@ fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { 4usize, concat!( "Size of template specialization: ", - stringify ! ( MaybeWrapped < :: std :: os :: raw :: c_int > ) + stringify!(MaybeWrapped<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(MaybeWrapped<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < MaybeWrapped < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( MaybeWrapped < :: std :: os :: raw :: c_int > ) ) ); } diff --git a/tests/expectations/tests/mangling-linux32.rs b/tests/expectations/tests/mangling-linux32.rs index 96186774b1..7fe8f33a7f 100644 --- a/tests/expectations/tests/mangling-linux32.rs +++ b/tests/expectations/tests/mangling-linux32.rs @@ -8,7 +8,7 @@ extern "C" { pub fn foo(); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -18,11 +18,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs index 96186774b1..7fe8f33a7f 100644 --- a/tests/expectations/tests/mangling-linux64.rs +++ b/tests/expectations/tests/mangling-linux64.rs @@ -8,7 +8,7 @@ extern "C" { pub fn foo(); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -18,11 +18,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs index 6f758141b5..7835dd928c 100644 --- a/tests/expectations/tests/mangling-macos.rs +++ b/tests/expectations/tests/mangling-macos.rs @@ -9,7 +9,7 @@ extern "C" { pub fn foo(); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -19,11 +19,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/mangling-win32.rs index e21228a1e6..2d2d7fcdbd 100644 --- a/tests/expectations/tests/mangling-win32.rs +++ b/tests/expectations/tests/mangling-win32.rs @@ -9,7 +9,7 @@ extern "C" { pub fn foo(); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -30,8 +30,3 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs index ffaf52cf2a..0d9c49faf7 100644 --- a/tests/expectations/tests/mangling-win64.rs +++ b/tests/expectations/tests/mangling-win64.rs @@ -8,7 +8,7 @@ extern "C" { pub fn foo(); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -18,11 +18,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs index e44b6e7dbc..f2eb6f9802 100644 --- a/tests/expectations/tests/method-mangling.rs +++ b/tests/expectations/tests/method-mangling.rs @@ -5,25 +5,30 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_int; } -impl Clone for Foo { - fn clone(&self) -> Self { *self } -} impl Foo { #[inline] - pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { Foo_type(self) } + pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { + Foo_type(self) + } } diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs index ad2c92fc6d..3f2d304e82 100644 --- a/tests/expectations/tests/module-whitelisted.rs +++ b/tests/expectations/tests/module-whitelisted.rs @@ -9,18 +9,21 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub _address: u8, } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Test ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Test ) )); - } - impl Clone for Test { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)) + ); } } diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index 589f8995a8..dfa378248e 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -5,22 +5,25 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub foo: usize, } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A ) ) . foo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A ) , "::" , stringify - ! ( foo ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(0 as *const A)).foo as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(A), "::", stringify!(foo)) + ); } diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 06f1df5068..86147bdd10 100644 --- a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -5,47 +5,56 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); -} -impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)) + ); } diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 9c98613769..7e841f7bd3 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -5,30 +5,43 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct C { pub m_member: ::std::os::raw::c_int, pub m_other: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . m_member as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( m_member ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . m_other as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( m_other ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).m_member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(C), + "::", + stringify!(m_member) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).m_other as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(C), + "::", + stringify!(m_other) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -37,15 +50,26 @@ pub struct NonCopiable { } #[test] fn bindgen_test_layout_NonCopiable() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( NonCopiable ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( NonCopiable ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const NonCopiable ) ) . m_member as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( NonCopiable ) , "::" , - stringify ! ( m_member ) )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NonCopiable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NonCopiable)) + ); + assert_eq!( + unsafe { &(*(0 as *const NonCopiable)).m_member as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(NonCopiable), + "::", + stringify!(m_member) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -54,18 +78,32 @@ pub struct NonCopiableWithNonCopiableMutableMember { } #[test] fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { - assert_eq!(::std::mem::size_of::() - , 4usize , concat ! ( - "Size of: " , stringify ! ( - NonCopiableWithNonCopiableMutableMember ) )); - assert_eq! (::std::mem::align_of::() - , 4usize , concat ! ( - "Alignment of " , stringify ! ( - NonCopiableWithNonCopiableMutableMember ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const NonCopiableWithNonCopiableMutableMember ) - ) . m_member as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - NonCopiableWithNonCopiableMutableMember ) , "::" , stringify ! - ( m_member ) )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(NonCopiableWithNonCopiableMutableMember) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(NonCopiableWithNonCopiableMutableMember) + ) + ); + assert_eq!( + unsafe { + &(*(0 as *const NonCopiableWithNonCopiableMutableMember)).m_member as *const _ as usize + }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(NonCopiableWithNonCopiableMutableMember), + "::", + stringify!(m_member) + ) + ); } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 6349748d00..13a9df0e78 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -9,7 +9,7 @@ pub mod root { #[allow(unused_imports)] use self::super::root; extern "C" { - #[link_name = "\u{1}_Z9top_levelv"] + #[link_name = "\u{1}_Z9top_levelv"] pub fn top_level(); } pub mod whatever { @@ -17,7 +17,7 @@ pub mod root { use self::super::super::root; pub type whatever_int_t = ::std::os::raw::c_int; extern "C" { - #[link_name = "\u{1}_ZN8whatever11in_whateverEv"] + #[link_name = "\u{1}_ZN8whatever11in_whateverEv"] pub fn in_whatever(); } } @@ -25,11 +25,11 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; extern "C" { - #[link_name = "\u{1}_ZN12_GLOBAL__N_13fooEv"] + #[link_name = "\u{1}_ZN12_GLOBAL__N_13fooEv"] pub fn foo(); } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct A { pub b: root::whatever::whatever_int_t, } @@ -52,16 +52,11 @@ pub mod root { ); } extern "C" { - #[link_name = "\u{1}_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"] + #[link_name = "\u{1}_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"] pub fn A_lets_hope_this_works( this: *mut root::_bindgen_mod_id_13::A, ) -> ::std::os::raw::c_int; } - impl Clone for A { - fn clone(&self) -> Self { - *self - } - } impl A { #[inline] pub unsafe fn lets_hope_this_works(&mut self) -> ::std::os::raw::c_int { @@ -99,15 +94,15 @@ pub mod root { } } extern "C" { - #[link_name = "\u{1}_ZN1w3hehEv"] + #[link_name = "\u{1}_ZN1w3hehEv"] pub fn heh() -> root::w::whatever_int_t; } extern "C" { - #[link_name = "\u{1}_ZN1w3fooEv"] + #[link_name = "\u{1}_ZN1w3fooEv"] pub fn foo() -> root::C<::std::os::raw::c_int>; } extern "C" { - #[link_name = "\u{1}_ZN1w4barrEv"] + #[link_name = "\u{1}_ZN1w4barrEv"] pub fn barr() -> root::C; } } diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 929732f68b..336723bbf0 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -5,79 +5,105 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Calc { pub w: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Calc() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Calc ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Calc ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Calc ) ) . w as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Calc ) , "::" , - stringify ! ( w ) )); -} -impl Clone for Calc { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Calc)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Calc)) + ); + assert_eq!( + unsafe { &(*(0 as *const Calc)).w as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Calc), + "::", + stringify!(w) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Test { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Test_Size { pub mWidth: Test_Size_Dimension, pub mHeight: Test_Size_Dimension, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Test_Size_Dimension { pub _base: Calc, } #[test] fn bindgen_test_layout_Test_Size_Dimension() { - assert_eq!(::std::mem::size_of::() , 4usize , concat - ! ( "Size of: " , stringify ! ( Test_Size_Dimension ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( Test_Size_Dimension ) )); -} -impl Clone for Test_Size_Dimension { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Test_Size_Dimension)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test_Size_Dimension)) + ); } #[test] fn bindgen_test_layout_Test_Size() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Test_Size ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Test_Size ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test_Size ) ) . mWidth as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Test_Size ) , "::" , - stringify ! ( mWidth ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test_Size ) ) . mHeight as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( Test_Size ) , "::" , - stringify ! ( mHeight ) )); -} -impl Clone for Test_Size { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Test_Size)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test_Size)) + ); + assert_eq!( + unsafe { &(*(0 as *const Test_Size)).mWidth as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Test_Size), + "::", + stringify!(mWidth) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const Test_Size)).mHeight as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(Test_Size), + "::", + stringify!(mHeight) + ) + ); } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Test ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Test ) )); -} -impl Clone for Test { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)) + ); } diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index d6579ec24e..4082610644 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -7,61 +7,75 @@ #[repr(C)] pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct nsISupports { pub vtable_: *const nsISupports__bindgen_vtable, } #[test] fn bindgen_test_layout_nsISupports() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsISupports ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsISupports ) )); -} -impl Clone for nsISupports { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsISupports)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsISupports)) + ); } impl Default for nsISupports { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_ZN11nsISupports14QueryInterfaceEv"] - pub fn nsISupports_QueryInterface(this: *mut ::std::os::raw::c_void) - -> *mut nsISupports; + pub fn nsISupports_QueryInterface(this: *mut ::std::os::raw::c_void) -> *mut nsISupports; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct nsIRunnable { pub _base: nsISupports, } #[test] fn bindgen_test_layout_nsIRunnable() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsIRunnable ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsIRunnable ) )); -} -impl Clone for nsIRunnable { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsIRunnable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsIRunnable)) + ); } impl Default for nsIRunnable { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Runnable { pub _base: nsIRunnable, } #[test] fn bindgen_test_layout_Runnable() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Runnable ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Runnable ) )); -} -impl Clone for Runnable { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Runnable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Runnable)) + ); } impl Default for Runnable { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 8021b831f2..0a494ba2e7 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -12,64 +12,88 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub foo: ::std::os::raw::c_int, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar_Baz { pub foo: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Bar_Baz() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar_Baz ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( Bar_Baz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar_Baz ) ) . foo as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar_Baz ) , - "::" , stringify ! ( foo ) )); - } - impl Clone for Bar_Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar_Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar_Baz)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar_Baz)).foo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar_Baz), + "::", + stringify!(foo) + ) + ); } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . foo as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( foo ) )); - } - impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).foo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub baz: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Baz ) ) . baz as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Baz ) , "::" , - stringify ! ( baz ) )); - } - impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)) + ); + assert_eq!( + unsafe { &(*(0 as *const Baz)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Baz), + "::", + stringify!(baz) + ) + ); } } } diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index e67b156beb..0260e54861 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -5,22 +5,25 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub s: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Foo ) ) . s as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Foo ) , "::" , - stringify ! ( s ) )); -} -impl Clone for Foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const Foo)).s as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(Foo), "::", stringify!(s)) + ); } diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/tests/expectations/tests/no-partialeq-opaque.rs index 8fd5451fb3..1a7941623d 100644 --- a/tests/expectations/tests/no-partialeq-opaque.rs +++ b/tests/expectations/tests/no-partialeq-opaque.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, } @@ -22,8 +22,3 @@ fn bindgen_test_layout_NoPartialEq() { concat!("Alignment of ", stringify!(NoPartialEq)) ); } -impl Clone for NoPartialEq { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/no-partialeq-whitelisted.rs b/tests/expectations/tests/no-partialeq-whitelisted.rs index f07864cea8..fb1437f1fe 100644 --- a/tests/expectations/tests/no-partialeq-whitelisted.rs +++ b/tests/expectations/tests/no-partialeq-whitelisted.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub i: ::std::os::raw::c_int, } @@ -32,8 +32,3 @@ fn bindgen_test_layout_NoPartialEq() { ) ); } -impl Clone for NoPartialEq { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index 41b3b18402..2708b21cfa 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -2,12 +2,14 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #![no_std] -mod libc { pub type c_int = i32; pub enum c_void {} } +mod libc { + pub type c_int = i32; + pub enum c_void {} +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct foo { pub a: libc::c_int, pub b: libc::c_int, @@ -15,29 +17,39 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::core::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::core::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . b as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( b ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( bar ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).b as *const _ as usize }, + 4usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).bar as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::core::mem::zeroed() } } + fn default() -> Self { + unsafe { ::core::mem::zeroed() } + } } diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index c367d8060d..c20876dcd1 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -7,7 +7,7 @@ pub type Array16 = u8; pub type ArrayInt4 = [u32; 4usize]; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct UsesArray { pub array_char_16: [u8; 16usize], pub array_bool_8: [u8; 8usize], @@ -15,26 +15,44 @@ pub struct UsesArray { } #[test] fn bindgen_test_layout_UsesArray() { - assert_eq!(::std::mem::size_of::() , 40usize , concat ! ( - "Size of: " , stringify ! ( UsesArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( UsesArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const UsesArray ) ) . array_char_16 as * const - _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( UsesArray ) , "::" , - stringify ! ( array_char_16 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const UsesArray ) ) . array_bool_8 as * const _ - as usize } , 16usize , concat ! ( - "Alignment of field: " , stringify ! ( UsesArray ) , "::" , - stringify ! ( array_bool_8 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const UsesArray ) ) . array_int_4 as * const _ - as usize } , 24usize , concat ! ( - "Alignment of field: " , stringify ! ( UsesArray ) , "::" , - stringify ! ( array_int_4 ) )); -} -impl Clone for UsesArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(UsesArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(UsesArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const UsesArray)).array_char_16 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(UsesArray), + "::", + stringify!(array_char_16) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const UsesArray)).array_bool_8 as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(UsesArray), + "::", + stringify!(array_bool_8) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const UsesArray)).array_int_4 as *const _ as usize }, + 24usize, + concat!( + "Alignment of field: ", + stringify!(UsesArray), + "::", + stringify!(array_int_4) + ) + ); } diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 0b3721efe7..52cad57d53 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -2,37 +2,46 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - -#![cfg(target_os="macos")] +#![cfg(target_os = "macos")] #[macro_use] extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; -pub trait Foo { } -impl Foo for id { } +pub trait Foo {} +impl Foo for id {} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct FooStruct { pub foo: *mut id, } #[test] fn bindgen_test_layout_FooStruct() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( FooStruct ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( FooStruct ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const FooStruct ) ) . foo as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( FooStruct ) , "::" , - stringify ! ( foo ) )); -} -impl Clone for FooStruct { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(FooStruct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(FooStruct)) + ); + assert_eq!( + unsafe { &(*(0 as *const FooStruct)).foo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(FooStruct), + "::", + stringify!(foo) + ) + ); } impl Default for FooStruct { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { pub fn fooFunc(foo: id); diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 4bc21afb67..5ac15b3859 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct C { pub _bitfield_1: u8, } @@ -22,11 +22,6 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl C { #[inline] pub fn a(&self) -> bool { diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 20b44d7e76..6cac967e7d 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -12,7 +12,7 @@ pub struct OpaqueTemplate {} /// Should derive Debug/Hash/PartialEq. #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsOpaqueTemplate { pub mBlah: u32, pub mBaz: ::std::os::raw::c_int, @@ -50,14 +50,9 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); } -impl Clone for ContainsOpaqueTemplate { - fn clone(&self) -> Self { - *self - } -} /// Should also derive Debug/Hash/PartialEq. #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct InheritsOpaqueTemplate { pub _base: u8, pub wow: *mut ::std::os::raw::c_char, @@ -85,11 +80,6 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { ) ); } -impl Clone for InheritsOpaqueTemplate { - fn clone(&self) -> Self { - *self - } -} impl Default for InheritsOpaqueTemplate { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 0981844689..45d8a7d826 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -23,7 +23,7 @@ pub mod root { } } #[repr(C)] - #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub c: ::std::os::raw::c_char, } @@ -45,13 +45,8 @@ pub mod root { concat!("Alignment of field: ", stringify!(Foo), "::", stringify!(c)) ); } - impl Clone for Foo { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub i: ::std::os::raw::c_int, } @@ -73,13 +68,8 @@ pub mod root { concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(i)) ); } - impl Clone for Bar { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsInstantiation { pub not_opaque: root::zoidberg::Template, } @@ -106,18 +96,13 @@ pub mod root { ) ); } - impl Clone for ContainsInstantiation { - fn clone(&self) -> Self { - *self - } - } impl Default for ContainsInstantiation { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] - #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsOpaqueInstantiation { pub opaque: u32, } @@ -146,11 +131,6 @@ pub mod root { ) ); } - impl Clone for ContainsOpaqueInstantiation { - fn clone(&self) -> Self { - *self - } - } } #[test] fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { @@ -159,9 +139,16 @@ pub mod root { 1usize, concat!( "Size of template specialization: ", - stringify ! ( root :: zoidberg :: Template < root :: zoidberg :: Foo > ) + stringify!(root::zoidberg::Template) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::zoidberg::Template) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: zoidberg :: Template < root :: zoidberg :: Foo > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: zoidberg :: Template < root :: zoidberg :: Foo > ) ) ); } } diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 480dba4855..02788d769c 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -16,7 +16,7 @@ impl Default for Template { } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsInstantiation { pub not_opaque: Template<::std::os::raw::c_char>, } @@ -43,18 +43,13 @@ fn bindgen_test_layout_ContainsInstantiation() { ) ); } -impl Clone for ContainsInstantiation { - fn clone(&self) -> Self { - *self - } -} impl Default for ContainsInstantiation { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsOpaqueInstantiation { pub opaque: u32, } @@ -81,11 +76,6 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { ) ); } -impl Clone for ContainsOpaqueInstantiation { - fn clone(&self) -> Self { - *self - } -} #[test] fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { assert_eq!( @@ -93,8 +83,15 @@ fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { 1usize, concat!( "Size of template specialization: ", - stringify ! ( Template < :: std :: os :: raw :: c_char > ) + stringify!(Template<::std::os::raw::c_char>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(Template<::std::os::raw::c_char>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Template < :: std :: os :: raw :: c_char > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Template < :: std :: os :: raw :: c_char > ) ) ); } diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index afae3127e6..87d91f3c4e 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -9,17 +9,20 @@ extern "C" { pub fn foo(c: *mut Container); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } #[test] fn bindgen_test_layout_Container() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Container ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Container ) )); -} -impl Clone for Container { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Container)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Container)) + ); } diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 49cfc5fc10..92d28e4d03 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -7,7 +7,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct opaque { pub _bindgen_opaque_blob: u32, } @@ -24,13 +24,8 @@ fn bindgen_test_layout_opaque() { concat!("Alignment of ", stringify!(opaque)) ); } -impl Clone for opaque { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub contained: opaque, } @@ -57,8 +52,3 @@ fn bindgen_test_layout_container() { ) ); } -impl Clone for container { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 6eb7b67235..cc8e247fc4 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -7,7 +7,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } @@ -24,17 +24,12 @@ fn bindgen_test_layout_OtherOpaque() { concat!("Alignment of ", stringify!(OtherOpaque)) ); } -impl Clone for OtherOpaque { - fn clone(&self) -> Self { - *self - } -} ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque {} #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq)] pub struct WithOpaquePtr { pub whatever: *mut u8, pub other: u32, @@ -83,11 +78,6 @@ fn bindgen_test_layout_WithOpaquePtr() { ) ); } -impl Clone for WithOpaquePtr { - fn clone(&self) -> Self { - *self - } -} impl Default for WithOpaquePtr { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index e29ad1ba57..400373f885 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct HasPrivate { pub mNotPrivate: ::std::os::raw::c_int, ///
@@ -13,54 +13,80 @@ pub struct HasPrivate { } #[test] fn bindgen_test_layout_HasPrivate() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( HasPrivate ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( HasPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const HasPrivate ) ) . mNotPrivate as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( HasPrivate ) , "::" , - stringify ! ( mNotPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const HasPrivate ) ) . mIsPrivate as * const _ - as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( HasPrivate ) , "::" , - stringify ! ( mIsPrivate ) )); -} -impl Clone for HasPrivate { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(HasPrivate)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(HasPrivate)) + ); + assert_eq!( + unsafe { &(*(0 as *const HasPrivate)).mNotPrivate as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(HasPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const HasPrivate)).mIsPrivate as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(HasPrivate), + "::", + stringify!(mIsPrivate) + ) + ); } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct VeryPrivate { mIsPrivate: ::std::os::raw::c_int, mIsAlsoPrivate: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_VeryPrivate() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( VeryPrivate ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( VeryPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const VeryPrivate ) ) . mIsPrivate as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" , - stringify ! ( mIsPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const VeryPrivate ) ) . mIsAlsoPrivate as * - const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" , - stringify ! ( mIsAlsoPrivate ) )); -} -impl Clone for VeryPrivate { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(VeryPrivate)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(VeryPrivate)) + ); + assert_eq!( + unsafe { &(*(0 as *const VeryPrivate)).mIsPrivate as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsPrivate) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const VeryPrivate)).mIsAlsoPrivate as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsAlsoPrivate) + ) + ); } ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct ContradictPrivate { ///
pub mNotPrivate: ::std::os::raw::c_int, @@ -68,21 +94,34 @@ pub struct ContradictPrivate { } #[test] fn bindgen_test_layout_ContradictPrivate() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( ContradictPrivate ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat - ! ( "Alignment of " , stringify ! ( ContradictPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictPrivate ) ) . mNotPrivate as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( ContradictPrivate ) , - "::" , stringify ! ( mNotPrivate ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const ContradictPrivate ) ) . mIsPrivate as * - const _ as usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( ContradictPrivate ) , - "::" , stringify ! ( mIsPrivate ) )); -} -impl Clone for ContradictPrivate { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ContradictPrivate)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContradictPrivate)) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictPrivate)).mNotPrivate as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const ContradictPrivate)).mIsPrivate as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mIsPrivate) + ) + ); } diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index ea5d0e18d1..14675a677f 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -8,26 +8,32 @@ pub const NSID_LENGTH: ::std::os::raw::c_uint = 10; #[repr(C)] pub struct nsID__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct nsID { pub vtable_: *const nsID__bindgen_vtable, } #[test] fn bindgen_test_layout_nsID() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsID ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsID ) )); -} -impl Clone for nsID { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsID)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsID)) + ); } impl Default for nsID { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_ZN4nsID16ToProvidedStringERA10_c"] - pub fn nsID_ToProvidedString(this: *mut ::std::os::raw::c_void, - aDest: - *mut [::std::os::raw::c_char; 10usize]); + pub fn nsID_ToProvidedString( + this: *mut ::std::os::raw::c_void, + aDest: *mut [::std::os::raw::c_char; 10usize], + ); } diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index c9e859114b..57a1187116 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -13,24 +13,32 @@ pub mod root { use self::super::super::root; ///
#[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub bazz: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . bazz as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( bazz ) )); - } - impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).bazz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(bazz) + ) + ); } } pub type ReferencesBar = root::foo::Bar; diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 49185e32be..5f85dc323f 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -12,7 +12,7 @@ pub struct nsTArray { pub y: ::std::os::raw::c_uint, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Test { pub a: nsTArray, } @@ -39,11 +39,6 @@ fn bindgen_test_layout_Test() { ) ); } -impl Clone for Test { - fn clone(&self) -> Self { - *self - } -} #[test] fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { assert_eq!( diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index e406cf33b5..b89568ecb6 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -10,28 +10,41 @@ pub struct JS_Zone { _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct JS_shadow_Zone { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_JS_shadow_Zone() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( JS_shadow_Zone ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( JS_shadow_Zone ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const JS_shadow_Zone ) ) . x as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::" - , stringify ! ( x ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const JS_shadow_Zone ) ) . y as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::" - , stringify ! ( y ) )); -} -impl Clone for JS_shadow_Zone { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(JS_shadow_Zone)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(JS_shadow_Zone)) + ); + assert_eq!( + unsafe { &(*(0 as *const JS_shadow_Zone)).x as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const JS_shadow_Zone)).y as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(y) + ) + ); } diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 7d105c2a85..96ad812977 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -22,7 +22,7 @@ pub mod root { pub i_am_wrapper_sentry: ::std::os::raw::c_int, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct sentry { pub i_am_plain_sentry: bool, } @@ -49,13 +49,8 @@ pub mod root { ) ); } - impl Clone for sentry { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper { pub _address: u8, } @@ -72,13 +67,8 @@ pub mod root { concat!("Alignment of ", stringify!(NotTemplateWrapper)) ); } - impl Clone for NotTemplateWrapper { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper_sentry { pub i_am_not_template_wrapper_sentry: ::std::os::raw::c_char, } @@ -96,8 +86,8 @@ pub mod root { ); assert_eq!( unsafe { - &(*(0 as *const NotTemplateWrapper_sentry)).i_am_not_template_wrapper_sentry as - *const _ as usize + &(*(0 as *const NotTemplateWrapper_sentry)).i_am_not_template_wrapper_sentry + as *const _ as usize }, 0usize, concat!( @@ -108,18 +98,13 @@ pub mod root { ) ); } - impl Clone for NotTemplateWrapper_sentry { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct InlineNotTemplateWrapper { pub _address: u8, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct InlineNotTemplateWrapper_sentry { pub i_am_inline_not_template_wrapper_sentry: bool, } @@ -138,8 +123,8 @@ pub mod root { assert_eq!( unsafe { &(*(0 as *const InlineNotTemplateWrapper_sentry)) - .i_am_inline_not_template_wrapper_sentry as *const _ as - usize + .i_am_inline_not_template_wrapper_sentry as *const _ + as usize }, 0usize, concat!( @@ -150,11 +135,6 @@ pub mod root { ) ); } - impl Clone for InlineNotTemplateWrapper_sentry { - fn clone(&self) -> Self { - *self - } - } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper() { assert_eq!( @@ -168,11 +148,6 @@ pub mod root { concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)) ); } - impl Clone for InlineNotTemplateWrapper { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InlineTemplateWrapper { @@ -184,12 +159,12 @@ pub mod root { pub i_am_inline_template_wrapper_sentry: ::std::os::raw::c_int, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleWrapper { pub _address: u8, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleWrapper_InnerDoubleWrapper { pub _address: u8, } @@ -212,11 +187,6 @@ pub mod root { ) ); } - impl Clone for OuterDoubleWrapper_InnerDoubleWrapper { - fn clone(&self) -> Self { - *self - } - } #[test] fn bindgen_test_layout_OuterDoubleWrapper() { assert_eq!( @@ -230,13 +200,8 @@ pub mod root { concat!("Alignment of ", stringify!(OuterDoubleWrapper)) ); } - impl Clone for OuterDoubleWrapper { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleWrapper_InnerDoubleWrapper_sentry { pub i_am_double_wrapper_sentry: ::std::os::raw::c_int, } @@ -272,23 +237,18 @@ pub mod root { ) ); } - impl Clone for OuterDoubleWrapper_InnerDoubleWrapper_sentry { - fn clone(&self) -> Self { - *self - } - } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleInlineWrapper { pub _address: u8, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper { pub _address: u8, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry { pub i_am_double_wrapper_inline_sentry: ::std::os::raw::c_int, } @@ -324,11 +284,6 @@ pub mod root { ) ); } - impl Clone for OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry { - fn clone(&self) -> Self { - *self - } - } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper() { assert_eq!( @@ -348,11 +303,6 @@ pub mod root { ) ); } - impl Clone for OuterDoubleInlineWrapper_InnerDoubleInlineWrapper { - fn clone(&self) -> Self { - *self - } - } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper() { assert_eq!( @@ -366,11 +316,6 @@ pub mod root { concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)) ); } - impl Clone for OuterDoubleInlineWrapper { - fn clone(&self) -> Self { - *self - } - } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -383,7 +328,7 @@ pub mod root { pub i_am_outside_namespace_wrapper_sentry: ::std::os::raw::c_int, } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct sentry { pub i_am_outside_namespace_sentry: ::std::os::raw::c_int, } @@ -410,9 +355,4 @@ pub mod root { ) ); } - impl Clone for sentry { - fn clone(&self) -> Self { - *self - } - } } diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index b3adbee6bc..9fa6c3ad77 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -5,22 +5,25 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct C { pub arr: [u32; 3usize], } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 12usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . arr as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( arr ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).arr as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(arr)) + ); } diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index db47ce6fd5..f20b9b3a7c 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -5,45 +5,63 @@ #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { pub val_a: *mut b, } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::
() , 8usize , concat ! ( - "Size of: " , stringify ! ( a ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const a ) ) . val_a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , stringify - ! ( val_a ) )); -} -impl Clone for a { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).val_a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(a), + "::", + stringify!(val_a) + ) + ); } impl Default for a { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct b { pub val_b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_b() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( b ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( b ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const b ) ) . val_b as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( b ) , "::" , stringify - ! ( val_b ) )); -} -impl Clone for b { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(b)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(b)) + ); + assert_eq!( + unsafe { &(*(0 as *const b)).val_b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(b), + "::", + stringify!(val_b) + ) + ); } diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index fb680b6988..1079bb3fa9 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -5,57 +5,78 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct typedef_named_struct { pub has_name: bool, } #[test] fn bindgen_test_layout_typedef_named_struct() { - assert_eq!(::std::mem::size_of::() , 1usize , concat - ! ( "Size of: " , stringify ! ( typedef_named_struct ) )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( typedef_named_struct ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const typedef_named_struct ) ) . has_name as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( typedef_named_struct ) - , "::" , stringify ! ( has_name ) )); -} -impl Clone for typedef_named_struct { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(typedef_named_struct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(typedef_named_struct)) + ); + assert_eq!( + unsafe { &(*(0 as *const typedef_named_struct)).has_name as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(typedef_named_struct), + "::", + stringify!(has_name) + ) + ); } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct _bindgen_ty_1 { pub no_name: *mut ::std::os::raw::c_void, } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! ( - "Size of: " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! ( - "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . no_name as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" - , stringify ! ( no_name ) )); -} -impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::<_bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const _bindgen_ty_1)).no_name as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(no_name) + ) + ); } impl Default for _bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub type struct_ptr_t = *mut _bindgen_ty_1; pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum typedef_named_enum { ENUM_HAS_NAME = 1, } +pub enum typedef_named_enum { + ENUM_HAS_NAME = 1, +} pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, } +pub enum _bindgen_ty_2 { + ENUM_IS_ANON = 0, +} pub type enum_ptr_t = *mut _bindgen_ty_2; pub type enum_ptr_ptr_t = *mut *mut _bindgen_ty_2; diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index e0dfe41d34..b40c1733d0 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -12,7 +12,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } @@ -39,11 +39,6 @@ pub mod root { ) ); } - impl Clone for typedef_struct { - fn clone(&self) -> Self { - *self - } - } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum typedef_enum { @@ -54,7 +49,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct _bindgen_ty_1 { pub foo: ::std::os::raw::c_int, } @@ -81,11 +76,6 @@ pub mod root { ) ); } - impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } - } pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 024eaac44d..b8726df08f 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -5,48 +5,69 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index fe3e8b0c97..8616ba5d75 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -5,80 +5,119 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub bar: [foo__bindgen_ty_1; 2usize], pub baz: [[[foo__bindgen_ty_2; 4usize]; 3usize]; 2usize], } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_foo__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_2 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat - ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) , - "::" , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . b as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) , - "::" , stringify ! ( b ) )); -} -impl Clone for foo__bindgen_ty_2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_2)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_2)).b as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 208usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } , - 16usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( baz ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 208usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).baz as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(baz) + ) + ); } diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 006de1cd4f..733721be38 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -5,51 +5,74 @@ #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub bar: *mut foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + 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 Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index a43ba4eef7..716461ea51 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, @@ -18,42 +18,67 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 0349d70ce1..839023ecbb 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -5,43 +5,59 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); } diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index af25e4e497..3cb92db746 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, @@ -18,37 +18,57 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index fffb938015..9c7b30072e 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct bitfield { pub _bitfield_1: u8, pub e: ::std::os::raw::c_int, @@ -34,11 +34,6 @@ fn bindgen_test_layout_bitfield() { ) ); } -impl Clone for bitfield { - fn clone(&self) -> Self { - *self - } -} impl bitfield { #[inline] pub fn a(&self) -> ::std::os::raw::c_ushort { diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 03046674d3..4a068de59e 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -5,88 +5,124 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct LittleArray { pub a: [::std::os::raw::c_int; 32usize], } #[test] fn bindgen_test_layout_LittleArray() { - assert_eq!(::std::mem::size_of::() , 128usize , concat ! ( - "Size of: " , stringify ! ( LittleArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( LittleArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const LittleArray ) ) . a as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( LittleArray ) , "::" , - stringify ! ( a ) )); -} -impl Clone for LittleArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(LittleArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LittleArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const LittleArray)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(LittleArray), + "::", + stringify!(a) + ) + ); } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct BigArray { pub a: [::std::os::raw::c_int; 33usize], } #[test] fn bindgen_test_layout_BigArray() { - assert_eq!(::std::mem::size_of::() , 132usize , concat ! ( - "Size of: " , stringify ! ( BigArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( BigArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const BigArray ) ) . a as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( BigArray ) , "::" , - stringify ! ( a ) )); -} -impl Clone for BigArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(BigArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(BigArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const BigArray)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(BigArray), + "::", + stringify!(a) + ) + ); } impl Default for BigArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct WithLittleArray { pub a: LittleArray, } #[test] fn bindgen_test_layout_WithLittleArray() { - assert_eq!(::std::mem::size_of::() , 128usize , concat ! - ( "Size of: " , stringify ! ( WithLittleArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! - ( "Alignment of " , stringify ! ( WithLittleArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithLittleArray ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithLittleArray ) , - "::" , stringify ! ( a ) )); -} -impl Clone for WithLittleArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(WithLittleArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithLittleArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithLittleArray)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithLittleArray), + "::", + stringify!(a) + ) + ); } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct WithBigArray { pub a: BigArray, } #[test] fn bindgen_test_layout_WithBigArray() { - assert_eq!(::std::mem::size_of::() , 132usize , concat ! ( - "Size of: " , stringify ! ( WithBigArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithBigArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , - stringify ! ( a ) )); -} -impl Clone for WithBigArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigArray)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); } impl Default for WithBigArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 0f2accba00..decc5934df 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -5,33 +5,45 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct S { pub large_array: [::std::os::raw::c_char; 33usize], } #[test] fn bindgen_test_layout_S() { - assert_eq!(::std::mem::size_of::() , 33usize , concat ! ( - "Size of: " , stringify ! ( S ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( S ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const S ) ) . large_array as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( S ) , "::" , stringify - ! ( large_array ) )); -} -impl Clone for S { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 33usize, + concat!("Size of: ", stringify!(S)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S)) + ); + assert_eq!( + unsafe { &(*(0 as *const S)).large_array as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); } impl Default for S { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct ST { pub large_array: [T; 33usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for ST { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for ST { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 7b82964f41..08fbc52c03 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -5,13 +5,13 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, @@ -19,39 +19,46 @@ pub union foo__bindgen_ty_1 { _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , - 4usize , concat ! ( - "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 ) - )); - assert_eq! (::std::mem::align_of::() , - 2usize , concat ! ( - "Alignment of " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c1 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c2 - as * const _ as usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c2 ) - )); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c2 as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d1: ::std::os::raw::c_uchar, pub d2: ::std::os::raw::c_uchar, @@ -60,75 +67,105 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::() , - 4usize , concat ! ( - "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 ) - )); - assert_eq! (::std::mem::align_of::() , - 1usize , concat ! ( - "Alignment of " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d1 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d2 - as * const _ as usize } , 1usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d2 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d3 - as * const _ as usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d3 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d4 - as * const _ as usize } , 3usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d4 ) - )); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d2 as *const _ as usize }, + 1usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d3 as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d4 as *const _ as usize }, + 3usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4) + ) + ); } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat - ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( a ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 1b3f4ca28a..b942ebd185 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -5,26 +5,31 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::() , 3usize , concat ! ( - "Size of: " , stringify ! ( a ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( a ) )); - assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , stringify - ! ( b ) )); - assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . c as * const _ as usize - } , 1usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , stringify - ! ( c ) )); -} -impl Clone for a { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(a), "::", stringify!(b)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).c as *const _ as usize }, + 1usize, + concat!("Alignment of field: ", stringify!(a), "::", stringify!(c)) + ); } diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index 47c99937f9..1549438776 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -5,48 +5,69 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat - ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . x as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( x ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . y as * const _ as - usize } , 4usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( y ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1)).x as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1)).y as *const _ as usize }, + 4usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(y) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 3f397b6ff3..c00fb17fd8 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -38,7 +38,7 @@ pub struct mozilla_Foo { _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct C { pub mB: B<::std::os::raw::c_uint>, pub mBConstPtr: B<*const ::std::os::raw::c_int>, @@ -214,11 +214,6 @@ fn bindgen_test_layout_C() { ) ); } -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -261,7 +256,7 @@ impl Default for Rooted { } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct RootedContainer { pub root: Rooted<*mut ::std::os::raw::c_void>, } @@ -288,11 +283,6 @@ fn bindgen_test_layout_RootedContainer() { ) ); } -impl Clone for RootedContainer { - fn clone(&self) -> Self { - *self - } -} impl Default for RootedContainer { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -348,7 +338,7 @@ impl Default for PODButContainsDtor { #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque {} #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct POD { pub opaque_member: u32, } @@ -375,11 +365,6 @@ fn bindgen_test_layout_POD() { ) ); } -impl Clone for POD { - fn clone(&self) -> Self { - *self - } -} ///
#[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -411,7 +396,7 @@ pub struct NestedContainer { pub inc: Incomplete, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for NestedContainer { +impl Default for NestedContainer { fn default() -> Self { unsafe { ::std::mem::zeroed() } } @@ -422,13 +407,13 @@ pub struct Incomplete { pub d: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Incomplete { +impl Default for Incomplete { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Untemplated { pub _address: u8, } @@ -445,11 +430,6 @@ fn bindgen_test_layout_Untemplated() { concat!("Alignment of ", stringify!(Untemplated)) ); } -impl Clone for Untemplated { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { @@ -514,103 +494,367 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { 24usize, concat!( "Size of template specialization: ", - stringify ! ( Foo < :: std :: os :: raw :: c_int > ) + stringify!(Foo<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); } #[test] fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_uint>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_uint>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const mozilla_Foo>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const mozilla_Foo>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<[*const mozilla_Foo; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[*const mozilla_Foo; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < bool > > ( ) , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( B < bool > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < bool > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < bool > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 1usize, + concat!("Size of template specialization: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(B) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Size of template specialization: " , stringify ! ( B < u16 > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < u16 > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 2usize, + concat!("Size of template specialization: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::>(), + 2usize, + concat!("Alignment of template specialization: ", stringify!(B)) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut *mut ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut *mut ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); } #[test] fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(WithDtor<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(WithDtor<::std::os::raw::c_int>) + ) + ); } diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index 88dc5d8b5f..10d91c1808 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -13,7 +13,7 @@ pub type Char = ::std::os::raw::c_char; pub type SChar = ::std::os::raw::c_schar; pub type UChar = ::std::os::raw::c_uchar; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Test { pub ch: ::std::os::raw::c_char, pub u: ::std::os::raw::c_uchar, @@ -95,6 +95,3 @@ fn bindgen_test_layout_Test() { "Alignment of field: " , stringify ! ( Test ) , "::" , stringify ! ( Ccd ) )); } -impl Clone for Test { - fn clone(&self) -> Self { *self } -} diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs index 63d64654f4..73902a4260 100644 --- a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs @@ -5,24 +5,32 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct dl_phdr_info { pub x: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_dl_phdr_info() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( dl_phdr_info ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( dl_phdr_info ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const dl_phdr_info ) ) . x as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( dl_phdr_info ) , "::" , - stringify ! ( x ) )); -} -impl Clone for dl_phdr_info { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(dl_phdr_info)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(dl_phdr_info)) + ); + assert_eq!( + unsafe { &(*(0 as *const dl_phdr_info)).x as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(dl_phdr_info), + "::", + stringify!(x) + ) + ); } extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 2bbdcbb148..7376aa7694 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -5,41 +5,50 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL ) - )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL ) - , "::" , stringify ! ( mIsLocalRef ) )); -} -impl Clone for mozilla_FragmentOrURL { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + unsafe { &(*(0 as *const mozilla_FragmentOrURL)).mIsLocalRef as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_Position { pub _address: u8, } #[test] fn bindgen_test_layout_mozilla_Position() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( mozilla_Position ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( mozilla_Position ) )); -} -impl Clone for mozilla_Position { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_Position)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_Position)) + ); } #[repr(C)] pub struct mozilla_StyleShapeSource { @@ -52,33 +61,47 @@ pub union mozilla_StyleShapeSource__bindgen_ty_1 { _bindgen_union_align: u64, } impl Default for mozilla_StyleShapeSource__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } impl Default for mozilla_StyleShapeSource { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub mFoo: *mut nsFoo, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( mFoo ) )); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).mFoo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(mFoo) + ) + ); } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct nsFoo { @@ -86,27 +109,48 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsFoo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsFoo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsFoo ) , "::" , - stringify ! ( mBar ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsFoo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsFoo)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsFoo)).mBar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); } impl Default for nsFoo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 8usize , - concat ! ( - "Size of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); - assert_eq!(::std::mem::align_of::() , 8usize , - concat ! ( - "Alignment of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); } diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index d1b0ccc23f..d9c61f7b6d 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -6,7 +6,7 @@ pub const __: ::std::os::raw::c_int = 10; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct ptr_t { pub __: [::std::os::raw::c_uchar; 8usize], } @@ -33,8 +33,3 @@ fn bindgen_test_layout_ptr_t() { ) ); } -impl Clone for ptr_t { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index cb8779bd3c..9776626c8d 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -9,27 +9,37 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Copy)] + #[derive(Copy, Clone)] pub union bar { pub baz: ::std::os::raw::c_int, _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const bar ) ) . baz as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( bar ) , "::" , - stringify ! ( baz ) )); - } - impl Clone for bar { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const bar)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); } impl Default for bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } } diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index ad41435d39..ee82188c36 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union U4 { pub _bitfield_1: u8, _bindgen_union_align: u32, @@ -23,11 +23,6 @@ fn bindgen_test_layout_U4() { concat!("Alignment of ", stringify!(U4)) ); } -impl Clone for U4 { - fn clone(&self) -> Self { - *self - } -} impl Default for U4 { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -76,7 +71,7 @@ impl U4 { } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union B { pub _bitfield_1: u32, _bindgen_union_align: u32, @@ -94,11 +89,6 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); } -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} impl Default for B { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 90319ee6bd..0c723b2a1c 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union nsStyleUnion { pub mInt: ::std::os::raw::c_int, pub mFloat: f32, @@ -14,29 +14,49 @@ pub union nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsStyleUnion ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsStyleUnion ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsStyleUnion ) ) . mInt as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" , - stringify ! ( mInt ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsStyleUnion ) ) . mFloat as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" , - stringify ! ( mFloat ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsStyleUnion ) ) . mPointer as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" , - stringify ! ( mPointer ) )); -} -impl Clone for nsStyleUnion { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsStyleUnion)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsStyleUnion)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsStyleUnion)).mInt as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mInt) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const nsStyleUnion)).mFloat as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mFloat) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const nsStyleUnion)).mPointer as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer) + ) + ); } impl Default for nsStyleUnion { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index d48538a0cb..87bcf6f3d6 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -5,52 +5,75 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, _bindgen_union_align: [u32; 2usize], } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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) + ) + ); } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index d759055bf3..ef5c16707c 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -5,14 +5,14 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_int, pub __bindgen_anon_1: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub _bitfield_1: u32, pub __bindgen_align: [u32; 0usize], @@ -30,11 +30,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); } -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { @@ -132,11 +127,6 @@ fn bindgen_test_layout_foo() { concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) ); } -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} impl Default for foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 29dbe7dc2e..92f8559587 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -5,13 +5,13 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, @@ -19,42 +19,67 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 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 } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 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 } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 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 Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 61b36d1aa7..1f5e493f72 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -5,14 +5,14 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union pixel { pub rgba: ::std::os::raw::c_uint, pub __bindgen_anon_1: pixel__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct pixel__bindgen_ty_1 { pub r: ::std::os::raw::c_uchar, pub g: ::std::os::raw::c_uchar, @@ -21,50 +21,82 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat - ! ( "Size of: " , stringify ! ( pixel__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( pixel__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . r as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , - "::" , stringify ! ( r ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . g as * const _ - as usize } , 1usize , concat ! ( - "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , - "::" , stringify ! ( g ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . b as * const _ - as usize } , 2usize , concat ! ( - "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . a as * const _ - as usize } , 3usize , concat ! ( - "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , - "::" , stringify ! ( a ) )); -} -impl Clone for pixel__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const pixel__bindgen_ty_1)).r as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const pixel__bindgen_ty_1)).g as *const _ as usize }, + 1usize, + concat!( + "Alignment of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const pixel__bindgen_ty_1)).b as *const _ as usize }, + 2usize, + concat!( + "Alignment of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const pixel__bindgen_ty_1)).a as *const _ as usize }, + 3usize, + concat!( + "Alignment of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a) + ) + ); } #[test] fn bindgen_test_layout_pixel() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( pixel ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( pixel ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const pixel ) ) . rgba as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( pixel ) , "::" , - stringify ! ( rgba ) )); -} -impl Clone for pixel { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pixel)) + ); + assert_eq!( + unsafe { &(*(0 as *const pixel)).rgba as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(pixel), + "::", + stringify!(rgba) + ) + ); } impl Default for pixel { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 4e0f4a18ba..ba0cf84ed8 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -5,14 +5,14 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, pub c: ::std::os::raw::c_uchar, @@ -20,42 +20,62 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 2usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 2usize , concat - ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( b ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . c as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , - "::" , stringify ! ( c ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1)).c as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(c) + ) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( a ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 9e86f42906..e0767ba273 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union WithBigArray { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_int; 33usize], @@ -13,29 +13,44 @@ pub union WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - assert_eq!(::std::mem::size_of::() , 132usize , concat ! ( - "Size of: " , stringify ! ( WithBigArray ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithBigArray ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , - stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigArray ) ) . b as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , - stringify ! ( b ) )); -} -impl Clone for WithBigArray { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigArray)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigArray)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigArray)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigArray), + "::", + stringify!(b) + ) + ); } impl Default for WithBigArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union WithBigArray2 { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_char; 33usize], @@ -43,29 +58,44 @@ pub union WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { - assert_eq!(::std::mem::size_of::() , 36usize , concat ! ( - "Size of: " , stringify ! ( WithBigArray2 ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithBigArray2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigArray2 ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::" - , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigArray2 ) ) . b as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::" - , stringify ! ( b ) )); -} -impl Clone for WithBigArray2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(WithBigArray2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray2)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigArray2)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigArray2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigArray2)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigArray2), + "::", + stringify!(b) + ) + ); } impl Default for WithBigArray2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union WithBigMember { pub a: ::std::os::raw::c_int, pub b: WithBigArray, @@ -73,24 +103,39 @@ pub union WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { - assert_eq!(::std::mem::size_of::() , 132usize , concat ! ( - "Size of: " , stringify ! ( WithBigMember ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( WithBigMember ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigMember ) ) . a as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigMember ) , "::" - , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const WithBigMember ) ) . b as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( WithBigMember ) , "::" - , stringify ! ( b ) )); -} -impl Clone for WithBigMember { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigMember)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigMember)) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigMember)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigMember), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const WithBigMember)).b as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(WithBigMember), + "::", + stringify!(b) + ) + ); } impl Default for WithBigMember { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 7ba8afcb41..1969a33c5c 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -5,20 +5,20 @@ #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct foo__bindgen_ty_1 { pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, pub b2: ::std::os::raw::c_ushort, @@ -26,35 +26,44 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , - 2usize , concat ! ( - "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 ) - )); - assert_eq! (::std::mem::align_of::() , - 2usize , concat ! ( - "Alignment of " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b1 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b2 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b2 ) - )); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b2 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2) + ) + ); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, @@ -62,61 +71,80 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::() , - 2usize , concat ! ( - "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 ) - )); - assert_eq! (::std::mem::align_of::() , - 2usize , concat ! ( - "Alignment of " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c1 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c1 ) - )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c2 - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c2 ) - )); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c2 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2) + ) + ); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! - ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::() , 2usize , concat - ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ); } impl Default for foo__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( a ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index dcd1e18ee1..b5d83c2e29 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, pub __bindgen_padding_0: u64, @@ -14,21 +14,29 @@ pub struct max_align_t { } #[test] fn bindgen_test_layout_max_align_t() { - assert_eq!(::std::mem::size_of::() , 32usize , concat ! ( - "Size of: " , stringify ! ( max_align_t ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const max_align_t ) ) . - __clang_max_align_nonce1 as * const _ as usize } , 0usize , - concat ! ( - "Alignment of field: " , stringify ! ( max_align_t ) , "::" , - stringify ! ( __clang_max_align_nonce1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const max_align_t ) ) . - __clang_max_align_nonce2 as * const _ as usize } , 16usize , - concat ! ( - "Alignment of field: " , stringify ! ( max_align_t ) , "::" , - stringify ! ( __clang_max_align_nonce2 ) )); -} -impl Clone for max_align_t { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(max_align_t)) + ); + assert_eq!( + unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce1 as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce2 as *const _ as usize }, + 16usize, + concat!( + "Alignment of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2) + ) + ); } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index b884f4f282..ebbfb9358c 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -6,7 +6,7 @@ extern crate core; #[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, @@ -14,34 +14,44 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::core::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::core::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . b as * const _ as usize } , - 4usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( b ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( bar ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).b as *const _ as usize }, + 4usize, + concat!("Alignment of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).bar as *const _ as usize }, + 8usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); } impl Default for foo { - fn default() -> Self { unsafe { ::core::mem::zeroed() } } + fn default() -> Self { + unsafe { ::core::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub union _bindgen_ty_1 { pub bar: ::std::os::raw::c_int, pub baz: ::std::os::raw::c_long, @@ -49,30 +59,44 @@ pub union _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::core::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! ( - "Size of: " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (::core::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! ( - "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" - , stringify ! ( bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" - , stringify ! ( baz ) )); -} -impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { *self } + assert_eq!( + ::core::mem::size_of::<_bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const _bindgen_ty_1)).bar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(bar) + ) + ); + assert_eq!( + unsafe { &(*(0 as *const _bindgen_ty_1)).baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(baz) + ) + ); } impl Default for _bindgen_ty_1 { - fn default() -> Self { unsafe { ::core::mem::zeroed() } } + fn default() -> Self { + unsafe { ::core::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}bazz"] pub static mut bazz: _bindgen_ty_1; } -pub type fooFunction = - ::core::option::Option; +pub type fooFunction = ::core::option::Option; diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 54ce92936a..d99526c7a7 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -5,29 +5,37 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub m_baz: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . m_baz as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( m_baz ) )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).m_baz as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(m_baz) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] pub fn Bar_Bar(this: *mut Bar, baz: ::std::os::raw::c_int); } -impl Clone for Bar { - fn clone(&self) -> Self { *self } -} impl Bar { #[inline] pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self { @@ -37,7 +45,7 @@ impl Bar { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } @@ -47,11 +55,14 @@ extern "C" { } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Baz ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Baz ) )); -} -impl Clone for Baz { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)) + ); } diff --git a/tests/expectations/tests/variadic-method.rs b/tests/expectations/tests/variadic-method.rs index 6ef20b7653..94dd73bee0 100644 --- a/tests/expectations/tests/variadic-method.rs +++ b/tests/expectations/tests/variadic-method.rs @@ -9,21 +9,24 @@ extern "C" { pub fn foo(fmt: *const ::std::os::raw::c_char, ...); } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } extern "C" { #[link_name = "\u{1}_ZN3Bar3fooEPKcz"] pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...); } -impl Clone for Bar { - fn clone(&self) -> Self { *self } -} diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index a4b87c7fdb..c75e9829c9 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -5,22 +5,30 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct foo { pub mMember: [::std::os::raw::c_longlong; 1usize], } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( foo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( foo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const foo ) ) . mMember as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( foo ) , "::" , - stringify ! ( mMember ) )); -} -impl Clone for foo { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(0 as *const foo)).mMember as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(foo), + "::", + stringify!(mMember) + ) + ); } diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index e177dca819..c4f7abfa98 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -5,79 +5,92 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct A { pub foo: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::
() , 4usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const A ) ) . foo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( A ) , "::" , stringify - ! ( foo ) )); -} -impl Clone for A { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(0 as *const A)).foo as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(A), "::", stringify!(foo)) + ); } #[repr(C)] pub struct B__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct B { pub vtable_: *const B__bindgen_vtable, pub bar: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( B ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( B ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const B ) ) . bar as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( B ) , "::" , stringify - ! ( bar ) )); -} -impl Clone for B { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { &(*(0 as *const B)).bar as *const _ as usize }, + 8usize, + concat!("Alignment of field: ", stringify!(B), "::", stringify!(bar)) + ); } impl Default for B { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct C__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct C { pub vtable_: *const C__bindgen_vtable, pub baz: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const C ) ) . baz as * const _ as usize } , - 8usize , concat ! ( - "Alignment of field: " , stringify ! ( C ) , "::" , stringify - ! ( baz ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(0 as *const C)).baz as *const _ as usize }, + 8usize, + concat!("Alignment of field: ", stringify!(C), "::", stringify!(baz)) + ); } impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct D { pub _base: C, pub _base_1: B, @@ -85,14 +98,19 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::() , 40usize , concat ! ( - "Size of: " , stringify ! ( D ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( D ) )); -} -impl Clone for D { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(D)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(D)) + ); } impl Default for D { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index ce9a198d62..376bae8a84 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -7,30 +7,33 @@ #[repr(C)] pub struct C__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct C { pub vtable_: *const C__bindgen_vtable, } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( C ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( C ) )); -} -impl Clone for C { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)) + ); } impl Default for C { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEc"] - pub fn C_do_thing(this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_char); + pub fn C_do_thing(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_char); } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEi"] - pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_int); + pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_int); } diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index 6684134287..f0720f2735 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -7,42 +7,52 @@ #[repr(C)] pub struct Base__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Base { pub vtable_: *const Base__bindgen_vtable, } #[test] fn bindgen_test_layout_Base() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Base ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Base ) )); -} -impl Clone for Base { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Base)) + ); } impl Default for Base { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_ZN4Base9AsDerivedEv"] pub fn Base_AsDerived(this: *mut ::std::os::raw::c_void) -> *mut Derived; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Derived { pub _base: Base, } #[test] fn bindgen_test_layout_Derived() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Derived ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Derived ) )); -} -impl Clone for Derived { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Derived)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Derived)) + ); } impl Default for Derived { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 7a0b18c958..ac73b70966 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -12,7 +12,7 @@ pub enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_ContextStrokeOpacity = 2, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct Weird { pub mStrokeDasharrayLength: ::std::os::raw::c_uint, pub _bitfield_1: [u16; 2usize], @@ -163,11 +163,6 @@ fn bindgen_test_layout_Weird() { ) ); } -impl Clone for Weird { - fn clone(&self) -> Self { - *self - } -} impl Default for Weird { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index daa6407bcf..d0e4c689c7 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -5,19 +5,22 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct UnknownUnits { pub _address: u8, } #[test] fn bindgen_test_layout_UnknownUnits() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( UnknownUnits ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( UnknownUnits ) )); -} -impl Clone for UnknownUnits { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(UnknownUnits)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(UnknownUnits)) + ); } pub type Float = f32; #[repr(C)] @@ -27,7 +30,9 @@ pub struct PointTyped { pub y: F, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for PointTyped { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for PointTyped { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub type IntPoint = PointTyped; diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index bdb35589e2..74c782f77c 100644 --- a/tests/expectations/tests/whitelist-namespaces-basic.rs +++ b/tests/expectations/tests/whitelist-namespaces-basic.rs @@ -15,19 +15,22 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Helper { pub _address: u8, } #[test] fn bindgen_test_layout_Helper() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! - ( "Size of: " , stringify ! ( Helper ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat - ! ( "Alignment of " , stringify ! ( Helper ) )); - } - impl Clone for Helper { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Helper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Helper)) + ); } } } diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs index e19bdba3e4..f1c86bde36 100644 --- a/tests/expectations/tests/whitelist-namespaces.rs +++ b/tests/expectations/tests/whitelist-namespaces.rs @@ -15,40 +15,51 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Helper { pub _address: u8, } #[test] fn bindgen_test_layout_Helper() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! - ( "Size of: " , stringify ! ( Helper ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat - ! ( "Alignment of " , stringify ! ( Helper ) )); - } - impl Clone for Helper { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Helper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Helper)) + ); } } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub helper: root::outer::inner::Helper, } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Test ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Test ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Test ) ) . helper as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Test ) , "::" , - stringify ! ( helper ) )); - } - impl Clone for Test { - fn clone(&self) -> Self { *self } + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)) + ); + assert_eq!( + unsafe { &(*(0 as *const Test)).helper as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Test), + "::", + stringify!(helper) + ) + ); } } } diff --git a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs index a7bbab74a1..32604b12ff 100644 --- a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub _address: u8, } @@ -22,13 +22,8 @@ fn bindgen_test_layout_NoPartialEq() { concat!("Alignment of ", stringify!(NoPartialEq)) ); } -impl Clone for NoPartialEq { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct WhitelistMe { pub a: NoPartialEq, } @@ -55,8 +50,3 @@ fn bindgen_test_layout_WhitelistMe() { ) ); } -impl Clone for WhitelistMe { - fn clone(&self) -> Self { - *self - } -} diff --git a/tests/expectations/tests/win32-thiscall_nightly.rs b/tests/expectations/tests/win32-thiscall_nightly.rs index 0fd1c00ddc..3b0140dcbf 100644 --- a/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/tests/expectations/tests/win32-thiscall_nightly.rs @@ -6,7 +6,7 @@ #![feature(abi_thiscall)] #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -31,11 +31,6 @@ extern "thiscall" { #[link_name = "\u{1}?test2@Foo@@QAEHH@Z"] pub fn Foo_test2(this: *mut Foo, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} impl Foo { #[inline] pub unsafe fn test(&mut self) { diff --git a/tests/headers/derive-clone.h b/tests/headers/derive-clone.h new file mode 100644 index 0000000000..a84d35cdd2 --- /dev/null +++ b/tests/headers/derive-clone.h @@ -0,0 +1,5 @@ + +/// This struct should derive `Clone`. +struct ShouldDeriveClone { + int large[33]; +}; diff --git a/tests/headers/derive-clone_1_0.h b/tests/headers/derive-clone_1_0.h new file mode 100644 index 0000000000..34ef40ae97 --- /dev/null +++ b/tests/headers/derive-clone_1_0.h @@ -0,0 +1,7 @@ +// bindgen-flags: --rust-target 1.0 + +/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct +/// should impl `Clone` "manually". +struct ShouldImplClone { + int large[33]; +};