diff --git a/src/ir/ty.rs b/src/ir/ty.rs index b3de1f036e..13b5f2eed0 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -532,7 +532,7 @@ impl<'a> CanDeriveCopy<'a> for Type { fn can_derive_copy(&self, ctx: &BindgenContext, item: &Item) -> bool { match self.kind { TypeKind::Array(t, len) => { - len <= RUST_DERIVE_IN_ARRAY_LIMIT && + len > 0 && t.can_derive_copy_in_array(ctx, ()) } TypeKind::ResolvedTypeRef(t) | diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 43e67153ac..26e6a62c3e 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -62,6 +62,7 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[repr(C)] +#[derive(Copy)] pub struct C { pub a: ::std::os::raw::c_int, pub big_array: [::std::os::raw::c_char; 33usize], @@ -82,6 +83,9 @@ fn bindgen_test_layout_C() { "Alignment of field: " , stringify ! ( C ) , "::" , stringify ! ( big_array ) )); } +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/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index a222500354..82be5c925c 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -38,7 +38,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } impl ::std::marker::Copy for __IncompleteArrayField { } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug)] pub struct rte_ring { pub memzone: *mut rte_memzone, pub prod: rte_ring_prod, @@ -92,9 +92,6 @@ fn bindgen_test_layout_rte_ring() { assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( "Alignment of " , stringify ! ( rte_ring ) )); } -impl Clone for rte_ring { - fn clone(&self) -> Self { *self } -} impl Default for rte_ring { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs index c3673cb1ba..28ebdc76f3 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -38,7 +38,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } impl ::std::marker::Copy for __IncompleteArrayField { } #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default)] pub struct header { pub proto: ::std::os::raw::c_char, pub size: ::std::os::raw::c_uint, @@ -50,6 +50,3 @@ fn bindgen_test_layout_header() { assert_eq!(::std::mem::size_of::
() , 16usize , concat ! ( "Size of: " , stringify ! ( header ) )); } -impl Clone for header { - fn clone(&self) -> Self { *self } -} diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index c254893894..102f1785fa 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -38,7 +38,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } impl ::std::marker::Copy for __IncompleteArrayField { } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug)] pub struct rte_kni_fifo { /// < Next position to be written pub write: ::std::os::raw::c_uint, @@ -59,9 +59,6 @@ fn bindgen_test_layout_rte_kni_fifo() { assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( "Alignment of " , stringify ! ( rte_kni_fifo ) )); } -impl Clone for rte_kni_fifo { - fn clone(&self) -> Self { *self } -} impl Default for rte_kni_fifo { 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 cc32c3cc57..a51e40bceb 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -727,6 +727,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)] pub struct rte_eth_vmdq_dcb_conf { /// < With DCB, 16 or 32 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -814,6 +815,9 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) , "::" , stringify ! ( dcb_tc ) )); } +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() } } } @@ -941,6 +945,7 @@ impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] +#[derive(Copy)] pub struct rte_eth_vmdq_rx_conf { /// < VMDq only mode, 8 or 64 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -1036,6 +1041,9 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) , "::" , stringify ! ( pool_map ) )); } +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() } } } @@ -1458,6 +1466,7 @@ impl Clone for rte_intr_conf { /// Depending upon the RX multi-queue mode, extra advanced /// configuration settings may be needed. #[repr(C)] +#[derive(Copy)] pub struct rte_eth_conf { /// < bitmap of ETH_LINK_SPEED_XXX of speeds to be /// used. ETH_LINK_SPEED_FIXED disables link @@ -1490,6 +1499,7 @@ pub struct rte_eth_conf { pub intr_conf: rte_intr_conf, } #[repr(C)] +#[derive(Copy)] pub struct rte_eth_conf__bindgen_ty_1 { /// < Port RSS configuration pub rss_conf: rte_eth_rss_conf, @@ -1531,6 +1541,9 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( vmdq_rx_conf ) )); } +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() } } } @@ -1625,6 +1638,9 @@ fn bindgen_test_layout_rte_eth_conf() { "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , stringify ! ( intr_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_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 6649f10d00..0d86acda61 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -317,7 +317,6 @@ impl Default for ip_frag_tbl_stat { } /// fragmentation table #[repr(C)] -#[derive(Copy)] pub struct rte_ip_frag_tbl { /// < ttl for table entries. pub max_cycles: u64, @@ -403,9 +402,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) , "::" , stringify ! ( pkt ) )); } -impl Clone for rte_ip_frag_tbl { - fn clone(&self) -> Self { *self } -} impl Default for rte_ip_frag_tbl { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 2b614c6d1b..77198c3500 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -58,7 +58,6 @@ impl Clone for rte_atomic16_t { } /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] -#[derive(Copy)] pub struct rte_mbuf { pub cacheline0: MARKER, /// < Virtual address of segment buffer. @@ -1078,9 +1077,6 @@ fn bindgen_test_layout_rte_mbuf() { "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , stringify ! ( timesync ) )); } -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/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index bbe7889830..b2a77b2772 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -25,6 +25,7 @@ impl Clone for LittleArray { fn clone(&self) -> Self { *self } } #[repr(C)] +#[derive(Copy)] pub struct BigArray { pub a: [::std::os::raw::c_int; 33usize], } @@ -40,6 +41,9 @@ fn bindgen_test_layout_BigArray() { "Alignment of field: " , stringify ! ( BigArray ) , "::" , stringify ! ( a ) )); } +impl Clone for BigArray { + fn clone(&self) -> Self { *self } +} impl Default for BigArray { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } @@ -64,6 +68,7 @@ impl Clone for WithLittleArray { fn clone(&self) -> Self { *self } } #[repr(C)] +#[derive(Copy)] pub struct WithBigArray { pub a: BigArray, } @@ -79,6 +84,9 @@ fn bindgen_test_layout_WithBigArray() { "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , stringify ! ( a ) )); } +impl Clone for WithBigArray { + fn clone(&self) -> Self { *self } +} impl Default for WithBigArray { 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 new file mode 100644 index 0000000000..0f2accba00 --- /dev/null +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -0,0 +1,37 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[repr(C)] +#[derive(Copy)] +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 } +} +impl Default for S { + 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() } } +} diff --git a/tests/headers/struct_with_large_array.hpp b/tests/headers/struct_with_large_array.hpp new file mode 100644 index 0000000000..fc67b333a3 --- /dev/null +++ b/tests/headers/struct_with_large_array.hpp @@ -0,0 +1,7 @@ +struct S { + char large_array[33]; +}; + +template struct ST { + T large_array[33]; +};