Skip to content

Commit a84e263

Browse files
committed
Derive Clone along with Copy on latest stable.
1 parent 17adb13 commit a84e263

File tree

203 files changed

+601
-2493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+601
-2493
lines changed

src/codegen/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,10 @@ impl CodeGenerator for CompInfo {
16421642
ctx.options().derive_copy
16431643
{
16441644
derives.push("Copy");
1645-
if used_template_params.is_some() {
1645+
1646+
if ctx.options().rust_features().builtin_clone_impls() ||
1647+
used_template_params.is_some()
1648+
{
16461649
// FIXME: This requires extra logic if you have a big array in a
16471650
// templated struct. The reason for this is that the magic:
16481651
// fn clone(&self) -> Self { *self }

src/features.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ macro_rules! rust_target_base {
9090
=> Stable_1_0 => 1.0;
9191
/// Rust stable 1.19
9292
=> Stable_1_19 => 1.19;
93+
/// Rust stable 1.21
94+
=> Stable_1_21 => 1.21;
9395
/// Nightly rust
9496
=> Nightly => nightly;
9597
);
@@ -100,7 +102,7 @@ rust_target_base!(rust_target_def);
100102
rust_target_base!(rust_target_values_def);
101103

102104
/// Latest stable release of Rust
103-
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_19;
105+
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21;
104106

105107
/// Create RustFeatures struct definition, new(), and a getter for each field
106108
macro_rules! rust_feature_def {
@@ -142,6 +144,8 @@ rust_feature_def!(
142144
=> const_fn;
143145
/// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
144146
=> thiscall_abi;
147+
/// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
148+
=> builtin_clone_impls;
145149
);
146150

147151
impl From<RustTarget> for RustFeatures {
@@ -152,6 +156,10 @@ impl From<RustTarget> for RustFeatures {
152156
features.untagged_union = true;
153157
}
154158

159+
if rust_target >= RustTarget::Stable_1_21 {
160+
features.builtin_clone_impls = true;
161+
}
162+
155163
if rust_target >= RustTarget::Nightly {
156164
features.const_fn = true;
157165
features.thiscall_abi = true;
@@ -183,6 +191,7 @@ mod test {
183191
fn str_to_target() {
184192
test_target("1.0", RustTarget::Stable_1_0);
185193
test_target("1.19", RustTarget::Stable_1_19);
194+
test_target("1.21", RustTarget::Stable_1_21);
186195
test_target("nightly", RustTarget::Nightly);
187196
}
188197
}

tests/expectations/tests/16-byte-alignment.rs

+7-42
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66

77
#[repr(C)]
8-
#[derive(Copy)]
8+
#[derive(Copy, Clone)]
99
pub struct rte_ipv4_tuple {
1010
pub src_addr: u32,
1111
pub dst_addr: u32,
1212
pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1,
1313
}
1414
#[repr(C)]
15-
#[derive(Copy)]
15+
#[derive(Copy, Clone)]
1616
pub union rte_ipv4_tuple__bindgen_ty_1 {
1717
pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
1818
pub sctp_tag: u32,
1919
_bindgen_union_align: u32,
2020
}
2121
#[repr(C)]
22-
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
22+
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
2323
pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
2424
pub dport: u16,
2525
pub sport: u16,
@@ -67,11 +67,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
6767
)
6868
);
6969
}
70-
impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
71-
fn clone(&self) -> Self {
72-
*self
73-
}
74-
}
7570
#[test]
7671
fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
7772
assert_eq!(
@@ -95,11 +90,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
9590
)
9691
);
9792
}
98-
impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
99-
fn clone(&self) -> Self {
100-
*self
101-
}
102-
}
10393
impl Default for rte_ipv4_tuple__bindgen_ty_1 {
10494
fn default() -> Self {
10595
unsafe { ::std::mem::zeroed() }
@@ -138,32 +128,27 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
138128
)
139129
);
140130
}
141-
impl Clone for rte_ipv4_tuple {
142-
fn clone(&self) -> Self {
143-
*self
144-
}
145-
}
146131
impl Default for rte_ipv4_tuple {
147132
fn default() -> Self {
148133
unsafe { ::std::mem::zeroed() }
149134
}
150135
}
151136
#[repr(C)]
152-
#[derive(Copy)]
137+
#[derive(Copy, Clone)]
153138
pub struct rte_ipv6_tuple {
154139
pub src_addr: [u8; 16usize],
155140
pub dst_addr: [u8; 16usize],
156141
pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1,
157142
}
158143
#[repr(C)]
159-
#[derive(Copy)]
144+
#[derive(Copy, Clone)]
160145
pub union rte_ipv6_tuple__bindgen_ty_1 {
161146
pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
162147
pub sctp_tag: u32,
163148
_bindgen_union_align: u32,
164149
}
165150
#[repr(C)]
166-
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
151+
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
167152
pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
168153
pub dport: u16,
169154
pub sport: u16,
@@ -211,11 +196,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
211196
)
212197
);
213198
}
214-
impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
215-
fn clone(&self) -> Self {
216-
*self
217-
}
218-
}
219199
#[test]
220200
fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
221201
assert_eq!(
@@ -239,11 +219,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
239219
)
240220
);
241221
}
242-
impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
243-
fn clone(&self) -> Self {
244-
*self
245-
}
246-
}
247222
impl Default for rte_ipv6_tuple__bindgen_ty_1 {
248223
fn default() -> Self {
249224
unsafe { ::std::mem::zeroed() }
@@ -282,18 +257,13 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
282257
)
283258
);
284259
}
285-
impl Clone for rte_ipv6_tuple {
286-
fn clone(&self) -> Self {
287-
*self
288-
}
289-
}
290260
impl Default for rte_ipv6_tuple {
291261
fn default() -> Self {
292262
unsafe { ::std::mem::zeroed() }
293263
}
294264
}
295265
#[repr(C)]
296-
#[derive(Copy)]
266+
#[derive(Copy, Clone)]
297267
pub union rte_thash_tuple {
298268
pub v4: rte_ipv4_tuple,
299269
pub v6: rte_ipv6_tuple,
@@ -327,11 +297,6 @@ fn bindgen_test_layout_rte_thash_tuple() {
327297
)
328298
);
329299
}
330-
impl Clone for rte_thash_tuple {
331-
fn clone(&self) -> Self {
332-
*self
333-
}
334-
}
335300
impl Default for rte_thash_tuple {
336301
fn default() -> Self {
337302
unsafe { ::std::mem::zeroed() }

tests/expectations/tests/accessors.rs

+6-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
#[repr(C)]
8-
#[derive(Debug, Default, Copy)]
8+
#[derive(Debug, Default, Copy, Clone)]
99
pub struct SomeAccessors {
1010
pub mNoAccessor: ::std::os::raw::c_int,
1111
/// <div rustbindgen accessor></div>
@@ -68,11 +68,6 @@ fn bindgen_test_layout_SomeAccessors() {
6868
)
6969
);
7070
}
71-
impl Clone for SomeAccessors {
72-
fn clone(&self) -> Self {
73-
*self
74-
}
75-
}
7671
impl SomeAccessors {
7772
#[inline]
7873
pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int {
@@ -97,7 +92,7 @@ impl SomeAccessors {
9792
}
9893
/// <div rustbindgen accessor></div>
9994
#[repr(C)]
100-
#[derive(Debug, Default, Copy)]
95+
#[derive(Debug, Default, Copy, Clone)]
10196
pub struct AllAccessors {
10297
pub mBothAccessors: ::std::os::raw::c_int,
10398
pub mAlsoBothAccessors: ::std::os::raw::c_int,
@@ -135,11 +130,6 @@ fn bindgen_test_layout_AllAccessors() {
135130
)
136131
);
137132
}
138-
impl Clone for AllAccessors {
139-
fn clone(&self) -> Self {
140-
*self
141-
}
142-
}
143133
impl AllAccessors {
144134
#[inline]
145135
pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int {
@@ -160,7 +150,7 @@ impl AllAccessors {
160150
}
161151
/// <div rustbindgen accessor="unsafe"></div>
162152
#[repr(C)]
163-
#[derive(Debug, Default, Copy)]
153+
#[derive(Debug, Default, Copy, Clone)]
164154
pub struct AllUnsafeAccessors {
165155
pub mBothAccessors: ::std::os::raw::c_int,
166156
pub mAlsoBothAccessors: ::std::os::raw::c_int,
@@ -198,11 +188,6 @@ fn bindgen_test_layout_AllUnsafeAccessors() {
198188
)
199189
);
200190
}
201-
impl Clone for AllUnsafeAccessors {
202-
fn clone(&self) -> Self {
203-
*self
204-
}
205-
}
206191
impl AllUnsafeAccessors {
207192
#[inline]
208193
pub unsafe fn get_mBothAccessors(&self) -> &::std::os::raw::c_int {
@@ -223,7 +208,7 @@ impl AllUnsafeAccessors {
223208
}
224209
/// <div rustbindgen accessor></div>
225210
#[repr(C)]
226-
#[derive(Debug, Default, Copy)]
211+
#[derive(Debug, Default, Copy, Clone)]
227212
pub struct ContradictAccessors {
228213
pub mBothAccessors: ::std::os::raw::c_int,
229214
/// <div rustbindgen accessor="false"></div>
@@ -286,11 +271,6 @@ fn bindgen_test_layout_ContradictAccessors() {
286271
)
287272
);
288273
}
289-
impl Clone for ContradictAccessors {
290-
fn clone(&self) -> Self {
291-
*self
292-
}
293-
}
294274
impl ContradictAccessors {
295275
#[inline]
296276
pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int {
@@ -315,7 +295,7 @@ impl ContradictAccessors {
315295
}
316296
/// <div rustbindgen accessor replaces="Replaced"></div>
317297
#[repr(C)]
318-
#[derive(Debug, Default, Copy)]
298+
#[derive(Debug, Default, Copy, Clone)]
319299
pub struct Replaced {
320300
pub mAccessor: ::std::os::raw::c_int,
321301
}
@@ -342,11 +322,6 @@ fn bindgen_test_layout_Replaced() {
342322
)
343323
);
344324
}
345-
impl Clone for Replaced {
346-
fn clone(&self) -> Self {
347-
*self
348-
}
349-
}
350325
impl Replaced {
351326
#[inline]
352327
pub fn get_mAccessor(&self) -> &::std::os::raw::c_int {
@@ -359,7 +334,7 @@ impl Replaced {
359334
}
360335
/// <div rustbindgen accessor></div>
361336
#[repr(C)]
362-
#[derive(Debug, Default, Copy)]
337+
#[derive(Debug, Default, Copy, Clone)]
363338
pub struct Wrapper {
364339
pub mReplaced: Replaced,
365340
}
@@ -386,11 +361,6 @@ fn bindgen_test_layout_Wrapper() {
386361
)
387362
);
388363
}
389-
impl Clone for Wrapper {
390-
fn clone(&self) -> Self {
391-
*self
392-
}
393-
}
394364
impl Wrapper {
395365
#[inline]
396366
pub fn get_mReplaced(&self) -> &Replaced {

tests/expectations/tests/annotation_hide.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/// <div rustbindgen opaque></div>
99
#[repr(C)]
10-
#[derive(Debug, Default, Copy)]
10+
#[derive(Debug, Default, Copy, Clone)]
1111
pub struct D {
1212
pub _bindgen_opaque_blob: u32,
1313
}
@@ -24,13 +24,8 @@ fn bindgen_test_layout_D() {
2424
concat!("Alignment of ", stringify!(D))
2525
);
2626
}
27-
impl Clone for D {
28-
fn clone(&self) -> Self {
29-
*self
30-
}
31-
}
3227
#[repr(C)]
33-
#[derive(Debug, Default, Copy)]
28+
#[derive(Debug, Default, Copy, Clone)]
3429
pub struct NotAnnotated {
3530
pub f: ::std::os::raw::c_int,
3631
}
@@ -57,8 +52,3 @@ fn bindgen_test_layout_NotAnnotated() {
5752
)
5853
);
5954
}
60-
impl Clone for NotAnnotated {
61-
fn clone(&self) -> Self {
62-
*self
63-
}
64-
}

tests/expectations/tests/anon_enum.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
#[repr(C)]
8-
#[derive(Debug, Default, Copy, PartialEq)]
8+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
99
pub struct Test {
1010
pub foo: ::std::os::raw::c_int,
1111
pub bar: f32,
@@ -49,11 +49,6 @@ fn bindgen_test_layout_Test() {
4949
)
5050
);
5151
}
52-
impl Clone for Test {
53-
fn clone(&self) -> Self {
54-
*self
55-
}
56-
}
5752
#[repr(u32)]
5853
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
5954
pub enum Baz {

tests/expectations/tests/anon_enum_trait.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum DataType__bindgen_ty_1 {
2424
generic_type = 0,
2525
}
2626
#[repr(C)]
27-
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
27+
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
2828
pub struct Foo {
2929
pub _address: u8,
3030
}
@@ -48,8 +48,3 @@ fn bindgen_test_layout_Foo() {
4848
concat!("Alignment of ", stringify!(Foo))
4949
);
5050
}
51-
impl Clone for Foo {
52-
fn clone(&self) -> Self {
53-
*self
54-
}
55-
}

0 commit comments

Comments
 (0)