Skip to content

Commit 2e2e733

Browse files
authored
Merge pull request #4038 from bossmc/derive-copy-clone
Use `#[derive]` for `Copy`/`Clone` in `s!` and friends
2 parents 0508535 + 73ce07c commit 2e2e733

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

libc-test/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,11 +4503,11 @@ fn test_linux(target: &str) {
45034503
true
45044504
}
45054505

4506-
// The `inotify_event` and `cmsghdr` types contain Flexible Array Member fields (the
4507-
// `name` and `data` fields respectively) which have unspecified calling convention.
4508-
// The roundtripping tests deliberately pass the structs by value to check "by value"
4509-
// layout consistency, but this would be UB for the these types.
4506+
// The following types contain Flexible Array Member fields which have unspecified calling
4507+
// convention. The roundtripping tests deliberately pass the structs by value to check "by
4508+
// value" layout consistency, but this would be UB for the these types.
45104509
"inotify_event" => true,
4510+
"fanotify_event_info_fid" => true,
45114511
"cmsghdr" => true,
45124512

45134513
// FIXME: the call ABI of max_align_t is incorrect on these platforms:

src/macros.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,11 @@ macro_rules! s {
8282
__item! {
8383
#[repr(C)]
8484
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
85+
#[derive(Copy, Clone)]
8586
#[allow(deprecated)]
8687
$(#[$attr])*
8788
pub struct $i { $($field)* }
8889
}
89-
#[allow(deprecated)]
90-
impl ::Copy for $i {}
91-
#[allow(deprecated)]
92-
impl ::Clone for $i {
93-
fn clone(&self) -> $i { *self }
94-
}
9590
);
9691
}
9792

@@ -106,13 +101,10 @@ macro_rules! s_paren {
106101
)*) => ($(
107102
__item! {
108103
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
104+
#[derive(Copy, Clone)]
109105
$(#[$attr])*
110106
pub struct $i ( $($field)* );
111107
}
112-
impl ::Copy for $i {}
113-
impl ::Clone for $i {
114-
fn clone(&self) -> $i { *self }
115-
}
116108
)*);
117109
}
118110

@@ -130,28 +122,19 @@ macro_rules! s_no_extra_traits {
130122
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
131123
__item! {
132124
#[repr(C)]
125+
#[derive(Copy, Clone)]
133126
$(#[$attr])*
134127
pub union $i { $($field)* }
135128
}
136-
137-
impl ::Copy for $i {}
138-
impl ::Clone for $i {
139-
fn clone(&self) -> $i { *self }
140-
}
141129
);
142130

143131
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
144132
__item! {
145133
#[repr(C)]
134+
#[derive(Copy, Clone)]
146135
$(#[$attr])*
147136
pub struct $i { $($field)* }
148137
}
149-
#[allow(deprecated)]
150-
impl ::Copy for $i {}
151-
#[allow(deprecated)]
152-
impl ::Clone for $i {
153-
fn clone(&self) -> $i { *self }
154-
}
155138
);
156139
}
157140

@@ -177,13 +160,10 @@ macro_rules! e {
177160
)*) => ($(
178161
__item! {
179162
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
163+
#[derive(Copy, Clone)]
180164
$(#[$attr])*
181165
pub enum $i { $($field)* }
182166
}
183-
impl ::Copy for $i {}
184-
impl ::Clone for $i {
185-
fn clone(&self) -> $i { *self }
186-
}
187167
)*);
188168
}
189169

0 commit comments

Comments
 (0)