Skip to content

Commit 44c548d

Browse files
committed
Use #[derive] for Copy/Clone in s! and friends.
Allows use of `#[cfg]` to skip items in an `s!` block without creating invalid, orphaned `impl` blocks.
1 parent 3a0b044 commit 44c548d

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

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)