Skip to content

Commit dd70d2b

Browse files
WiSaGaNtmfink
authored andcommitted
Support deriving copy for large array
1 parent e335298 commit dd70d2b

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

src/ir/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ impl<'a> CanDeriveCopy<'a> for Type {
531531

532532
fn can_derive_copy(&self, ctx: &BindgenContext, item: &Item) -> bool {
533533
match self.kind {
534-
TypeKind::Array(t, len) => {
535-
len <= RUST_DERIVE_IN_ARRAY_LIMIT &&
534+
TypeKind::Array(t, _) => {
536535
t.can_derive_copy_in_array(ctx, ())
537536
}
538537
TypeKind::ResolvedTypeRef(t) |

tests/expectations/tests/class.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
6262
}
6363
}
6464
#[repr(C)]
65+
#[derive(Copy)]
6566
pub struct C {
6667
pub a: ::std::os::raw::c_int,
6768
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -82,10 +83,14 @@ fn bindgen_test_layout_C() {
8283
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
8384
! ( big_array ) ));
8485
}
86+
impl Clone for C {
87+
fn clone(&self) -> Self { *self }
88+
}
8589
impl Default for C {
8690
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
8791
}
8892
#[repr(C)]
93+
#[derive(Copy)]
8994
pub struct C_with_zero_length_array {
9095
pub a: ::std::os::raw::c_int,
9196
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -118,10 +123,14 @@ fn bindgen_test_layout_C_with_zero_length_array() {
118123
C_with_zero_length_array ) , "::" , stringify ! (
119124
zero_length_array ) ));
120125
}
126+
impl Clone for C_with_zero_length_array {
127+
fn clone(&self) -> Self { *self }
128+
}
121129
impl Default for C_with_zero_length_array {
122130
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
123131
}
124132
#[repr(C)]
133+
#[derive(Copy)]
125134
pub struct C_with_incomplete_array {
126135
pub a: ::std::os::raw::c_int,
127136
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -136,10 +145,14 @@ fn bindgen_test_layout_C_with_incomplete_array() {
136145
concat ! (
137146
"Alignment of " , stringify ! ( C_with_incomplete_array ) ));
138147
}
148+
impl Clone for C_with_incomplete_array {
149+
fn clone(&self) -> Self { *self }
150+
}
139151
impl Default for C_with_incomplete_array {
140152
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
141153
}
142154
#[repr(C)]
155+
#[derive(Copy)]
143156
pub struct C_with_zero_length_array_and_incomplete_array {
144157
pub a: ::std::os::raw::c_int,
145158
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -157,6 +170,9 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
157170
"Alignment of " , stringify ! (
158171
C_with_zero_length_array_and_incomplete_array ) ));
159172
}
173+
impl Clone for C_with_zero_length_array_and_incomplete_array {
174+
fn clone(&self) -> Self { *self }
175+
}
160176
impl Default for C_with_zero_length_array_and_incomplete_array {
161177
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
162178
}
@@ -178,6 +194,7 @@ fn bindgen_test_layout_WithDtor() {
178194
stringify ! ( b ) ));
179195
}
180196
#[repr(C)]
197+
#[derive(Copy)]
181198
pub struct IncompleteArrayNonCopiable {
182199
pub whatever: *mut ::std::os::raw::c_void,
183200
pub incomplete_array: __IncompleteArrayField<C>,
@@ -192,6 +209,9 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() {
192209
"Alignment of " , stringify ! ( IncompleteArrayNonCopiable )
193210
));
194211
}
212+
impl Clone for IncompleteArrayNonCopiable {
213+
fn clone(&self) -> Self { *self }
214+
}
195215
impl Default for IncompleteArrayNonCopiable {
196216
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
197217
}

tests/expectations/tests/layout_eth_conf.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ pub enum rte_eth_nb_pools {
727727
/// A default pool may be used, if desired, to route all traffic which
728728
/// does not match the vlan filter rules.
729729
#[repr(C)]
730+
#[derive(Copy)]
730731
pub struct rte_eth_vmdq_dcb_conf {
731732
/// < With DCB, 16 or 32 pools
732733
pub nb_queue_pools: rte_eth_nb_pools,
@@ -814,6 +815,9 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() {
814815
"Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf )
815816
, "::" , stringify ! ( dcb_tc ) ));
816817
}
818+
impl Clone for rte_eth_vmdq_dcb_conf {
819+
fn clone(&self) -> Self { *self }
820+
}
817821
impl Default for rte_eth_vmdq_dcb_conf {
818822
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
819823
}
@@ -941,6 +945,7 @@ impl Default for rte_eth_vmdq_tx_conf {
941945
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
942946
}
943947
#[repr(C)]
948+
#[derive(Copy)]
944949
pub struct rte_eth_vmdq_rx_conf {
945950
/// < VMDq only mode, 8 or 64 pools
946951
pub nb_queue_pools: rte_eth_nb_pools,
@@ -1036,6 +1041,9 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() {
10361041
"Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf )
10371042
, "::" , stringify ! ( pool_map ) ));
10381043
}
1044+
impl Clone for rte_eth_vmdq_rx_conf {
1045+
fn clone(&self) -> Self { *self }
1046+
}
10391047
impl Default for rte_eth_vmdq_rx_conf {
10401048
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
10411049
}
@@ -1458,6 +1466,7 @@ impl Clone for rte_intr_conf {
14581466
/// Depending upon the RX multi-queue mode, extra advanced
14591467
/// configuration settings may be needed.
14601468
#[repr(C)]
1469+
#[derive(Copy)]
14611470
pub struct rte_eth_conf {
14621471
/// < bitmap of ETH_LINK_SPEED_XXX of speeds to be
14631472
/// used. ETH_LINK_SPEED_FIXED disables link
@@ -1490,6 +1499,7 @@ pub struct rte_eth_conf {
14901499
pub intr_conf: rte_intr_conf,
14911500
}
14921501
#[repr(C)]
1502+
#[derive(Copy)]
14931503
pub struct rte_eth_conf__bindgen_ty_1 {
14941504
/// < Port RSS configuration
14951505
pub rss_conf: rte_eth_rss_conf,
@@ -1531,6 +1541,9 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() {
15311541
rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! (
15321542
vmdq_rx_conf ) ));
15331543
}
1544+
impl Clone for rte_eth_conf__bindgen_ty_1 {
1545+
fn clone(&self) -> Self { *self }
1546+
}
15341547
impl Default for rte_eth_conf__bindgen_ty_1 {
15351548
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
15361549
}
@@ -1625,6 +1638,9 @@ fn bindgen_test_layout_rte_eth_conf() {
16251638
"Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" ,
16261639
stringify ! ( intr_conf ) ));
16271640
}
1641+
impl Clone for rte_eth_conf {
1642+
fn clone(&self) -> Self { *self }
1643+
}
16281644
impl Default for rte_eth_conf {
16291645
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
16301646
}

tests/expectations/tests/struct_with_derive_debug.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Clone for LittleArray {
2525
fn clone(&self) -> Self { *self }
2626
}
2727
#[repr(C)]
28+
#[derive(Copy)]
2829
pub struct BigArray {
2930
pub a: [::std::os::raw::c_int; 33usize],
3031
}
@@ -40,6 +41,9 @@ fn bindgen_test_layout_BigArray() {
4041
"Alignment of field: " , stringify ! ( BigArray ) , "::" ,
4142
stringify ! ( a ) ));
4243
}
44+
impl Clone for BigArray {
45+
fn clone(&self) -> Self { *self }
46+
}
4347
impl Default for BigArray {
4448
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
4549
}
@@ -64,6 +68,7 @@ impl Clone for WithLittleArray {
6468
fn clone(&self) -> Self { *self }
6569
}
6670
#[repr(C)]
71+
#[derive(Copy)]
6772
pub struct WithBigArray {
6873
pub a: BigArray,
6974
}
@@ -79,6 +84,9 @@ fn bindgen_test_layout_WithBigArray() {
7984
"Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
8085
stringify ! ( a ) ));
8186
}
87+
impl Clone for WithBigArray {
88+
fn clone(&self) -> Self { *self }
89+
}
8290
impl Default for WithBigArray {
8391
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
8492
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Copy)]
9+
pub struct S {
10+
pub large_array: [::std::os::raw::c_char; 33usize],
11+
}
12+
#[test]
13+
fn bindgen_test_layout_S() {
14+
assert_eq!(::std::mem::size_of::<S>() , 33usize , concat ! (
15+
"Size of: " , stringify ! ( S ) ));
16+
assert_eq! (::std::mem::align_of::<S>() , 1usize , concat ! (
17+
"Alignment of " , stringify ! ( S ) ));
18+
assert_eq! (unsafe {
19+
& ( * ( 0 as * const S ) ) . large_array as * const _ as usize
20+
} , 0usize , concat ! (
21+
"Alignment of field: " , stringify ! ( S ) , "::" , stringify
22+
! ( large_array ) ));
23+
}
24+
impl Clone for S {
25+
fn clone(&self) -> Self { *self }
26+
}
27+
impl Default for S {
28+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
29+
}
30+
#[repr(C)]
31+
pub struct ST<T> {
32+
pub large_array: [T; 33usize],
33+
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
34+
}
35+
impl <T> Default for ST<T> {
36+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct S {
2+
char large_array[33];
3+
};
4+
5+
template<typename T> struct ST {
6+
T large_array[33];
7+
};

0 commit comments

Comments
 (0)