Skip to content

Commit 035591d

Browse files
WiSaGaNtmfink
authored andcommitted
Not derive Copy for C flexible array member
1 parent dd70d2b commit 035591d

File tree

7 files changed

+5
-37
lines changed

7 files changed

+5
-37
lines changed

src/ir/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ 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, _) => {
534+
TypeKind::Array(t, len) => {
535+
len > 0 &&
535536
t.can_derive_copy_in_array(ctx, ())
536537
}
537538
TypeKind::ResolvedTypeRef(t) |

tests/expectations/tests/class.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ impl Default for C {
9090
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
9191
}
9292
#[repr(C)]
93-
#[derive(Copy)]
9493
pub struct C_with_zero_length_array {
9594
pub a: ::std::os::raw::c_int,
9695
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -123,14 +122,10 @@ fn bindgen_test_layout_C_with_zero_length_array() {
123122
C_with_zero_length_array ) , "::" , stringify ! (
124123
zero_length_array ) ));
125124
}
126-
impl Clone for C_with_zero_length_array {
127-
fn clone(&self) -> Self { *self }
128-
}
129125
impl Default for C_with_zero_length_array {
130126
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
131127
}
132128
#[repr(C)]
133-
#[derive(Copy)]
134129
pub struct C_with_incomplete_array {
135130
pub a: ::std::os::raw::c_int,
136131
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -145,14 +140,10 @@ fn bindgen_test_layout_C_with_incomplete_array() {
145140
concat ! (
146141
"Alignment of " , stringify ! ( C_with_incomplete_array ) ));
147142
}
148-
impl Clone for C_with_incomplete_array {
149-
fn clone(&self) -> Self { *self }
150-
}
151143
impl Default for C_with_incomplete_array {
152144
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
153145
}
154146
#[repr(C)]
155-
#[derive(Copy)]
156147
pub struct C_with_zero_length_array_and_incomplete_array {
157148
pub a: ::std::os::raw::c_int,
158149
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -170,9 +161,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
170161
"Alignment of " , stringify ! (
171162
C_with_zero_length_array_and_incomplete_array ) ));
172163
}
173-
impl Clone for C_with_zero_length_array_and_incomplete_array {
174-
fn clone(&self) -> Self { *self }
175-
}
176164
impl Default for C_with_zero_length_array_and_incomplete_array {
177165
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
178166
}
@@ -194,7 +182,6 @@ fn bindgen_test_layout_WithDtor() {
194182
stringify ! ( b ) ));
195183
}
196184
#[repr(C)]
197-
#[derive(Copy)]
198185
pub struct IncompleteArrayNonCopiable {
199186
pub whatever: *mut ::std::os::raw::c_void,
200187
pub incomplete_array: __IncompleteArrayField<C>,
@@ -209,9 +196,6 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() {
209196
"Alignment of " , stringify ! ( IncompleteArrayNonCopiable )
210197
));
211198
}
212-
impl Clone for IncompleteArrayNonCopiable {
213-
fn clone(&self) -> Self { *self }
214-
}
215199
impl Default for IncompleteArrayNonCopiable {
216200
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
217201
}

tests/expectations/tests/issue-643-inner-struct.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
3838
}
3939
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
4040
#[repr(C)]
41-
#[derive(Debug, Copy)]
41+
#[derive(Debug)]
4242
pub struct rte_ring {
4343
pub memzone: *mut rte_memzone,
4444
pub prod: rte_ring_prod,
@@ -92,9 +92,6 @@ fn bindgen_test_layout_rte_ring() {
9292
assert_eq! (::std::mem::align_of::<rte_ring>() , 8usize , concat ! (
9393
"Alignment of " , stringify ! ( rte_ring ) ));
9494
}
95-
impl Clone for rte_ring {
96-
fn clone(&self) -> Self { *self }
97-
}
9895
impl Default for rte_ring {
9996
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
10097
}

tests/expectations/tests/layout.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
3838
}
3939
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
4040
#[repr(C, packed)]
41-
#[derive(Debug, Default, Copy)]
41+
#[derive(Debug, Default)]
4242
pub struct header {
4343
pub proto: ::std::os::raw::c_char,
4444
pub size: ::std::os::raw::c_uint,
@@ -50,6 +50,3 @@ fn bindgen_test_layout_header() {
5050
assert_eq!(::std::mem::size_of::<header>() , 16usize , concat ! (
5151
"Size of: " , stringify ! ( header ) ));
5252
}
53-
impl Clone for header {
54-
fn clone(&self) -> Self { *self }
55-
}

tests/expectations/tests/layout_align.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
3838
}
3939
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
4040
#[repr(C)]
41-
#[derive(Debug, Copy)]
41+
#[derive(Debug)]
4242
pub struct rte_kni_fifo {
4343
/// < Next position to be written
4444
pub write: ::std::os::raw::c_uint,
@@ -59,9 +59,6 @@ fn bindgen_test_layout_rte_kni_fifo() {
5959
assert_eq! (::std::mem::align_of::<rte_kni_fifo>() , 8usize , concat ! (
6060
"Alignment of " , stringify ! ( rte_kni_fifo ) ));
6161
}
62-
impl Clone for rte_kni_fifo {
63-
fn clone(&self) -> Self { *self }
64-
}
6562
impl Default for rte_kni_fifo {
6663
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
6764
}

tests/expectations/tests/layout_large_align_field.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ impl Default for ip_frag_tbl_stat {
317317
}
318318
/// fragmentation table
319319
#[repr(C)]
320-
#[derive(Copy)]
321320
pub struct rte_ip_frag_tbl {
322321
/// < ttl for table entries.
323322
pub max_cycles: u64,
@@ -403,9 +402,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() {
403402
"Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
404403
"::" , stringify ! ( pkt ) ));
405404
}
406-
impl Clone for rte_ip_frag_tbl {
407-
fn clone(&self) -> Self { *self }
408-
}
409405
impl Default for rte_ip_frag_tbl {
410406
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
411407
}

tests/expectations/tests/layout_mbuf.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl Clone for rte_atomic16_t {
5858
}
5959
/// The generic rte_mbuf, containing a packet mbuf.
6060
#[repr(C)]
61-
#[derive(Copy)]
6261
pub struct rte_mbuf {
6362
pub cacheline0: MARKER,
6463
/// < Virtual address of segment buffer.
@@ -1078,9 +1077,6 @@ fn bindgen_test_layout_rte_mbuf() {
10781077
"Alignment of field: " , stringify ! ( rte_mbuf ) , "::" ,
10791078
stringify ! ( timesync ) ));
10801079
}
1081-
impl Clone for rte_mbuf {
1082-
fn clone(&self) -> Self { *self }
1083-
}
10841080
impl Default for rte_mbuf {
10851081
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
10861082
}

0 commit comments

Comments
 (0)