@@ -37,7 +37,7 @@ impl Parse for Newtype {
37
37
braced ! ( body in input) ;
38
38
39
39
// Any additional `#[derive]` macro paths to apply
40
- let mut derive_paths: Option < Vec < Path > > = None ;
40
+ let mut derive_paths: Vec < Path > = Vec :: new ( ) ;
41
41
let mut debug_format: Option < DebugFormat > = None ;
42
42
let mut max = None ;
43
43
let mut consts = Vec :: new ( ) ;
@@ -62,28 +62,23 @@ impl Parse for Newtype {
62
62
let derives: Punctuated < Path , Token ! [ , ] > =
63
63
derives. parse_terminated ( Path :: parse) ?;
64
64
try_comma ( ) ?;
65
- if let Some ( old) = derive_paths. replace ( derives. into_iter ( ) . collect ( ) ) {
66
- panic ! ( "Specified multiple derives: {:?}" , old) ;
67
- }
65
+ derive_paths. extend ( derives) ;
68
66
continue ;
69
67
}
70
68
if body. lookahead1 ( ) . peek ( kw:: DEBUG_FORMAT ) {
71
69
body. parse :: < kw:: DEBUG_FORMAT > ( ) ?;
72
70
body. parse :: < Token ! [ =] > ( ) ?;
73
- if body. lookahead1 ( ) . peek ( kw:: custom) {
71
+ let new_debug_format = if body. lookahead1 ( ) . peek ( kw:: custom) {
74
72
body. parse :: < kw:: custom > ( ) ?;
75
- if let Some ( old) = debug_format. replace ( DebugFormat :: Custom ) {
76
- panic ! ( "Specified multiple debug format options: {:?}" , old) ;
77
- }
73
+ DebugFormat :: Custom
78
74
} else {
79
75
let format_str: LitStr = body. parse ( ) ?;
80
- if let Some ( old) =
81
- debug_format. replace ( DebugFormat :: Format ( format_str. value ( ) ) )
82
- {
83
- panic ! ( "Specified multiple debug format options: {:?}" , old) ;
84
- }
85
- }
76
+ DebugFormat :: Format ( format_str. value ( ) )
77
+ } ;
86
78
try_comma ( ) ?;
79
+ if let Some ( old) = debug_format. replace ( new_debug_format) {
80
+ panic ! ( "Specified multiple debug format options: {:?}" , old) ;
81
+ }
87
82
continue ;
88
83
}
89
84
if body. lookahead1 ( ) . peek ( kw:: MAX ) {
@@ -121,7 +116,6 @@ impl Parse for Newtype {
121
116
}
122
117
}
123
118
124
- let derive_paths = derive_paths. unwrap_or_else ( Vec :: new) ;
125
119
let debug_format = debug_format. unwrap_or ( DebugFormat :: Format ( "{}" . to_string ( ) ) ) ;
126
120
// shave off 256 indices at the end to allow space for packing these indices into enums
127
121
let max = max. unwrap_or_else ( || Lit :: Int ( LitInt :: new ( "0xFFFF_FF00" , Span :: call_site ( ) ) ) ) ;
@@ -158,21 +152,14 @@ impl Parse for Newtype {
158
152
159
153
Ok ( Self ( quote ! {
160
154
#( #attrs) *
161
- #[ derive( Copy , PartialEq , Eq , Hash , PartialOrd , Ord , #( #derive_paths) , * ) ]
155
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord , #( #derive_paths) , * ) ]
162
156
#[ rustc_layout_scalar_valid_range_end( #max) ]
163
157
#vis struct #name {
164
158
private: u32 ,
165
159
}
166
160
167
161
#( #consts) *
168
162
169
- impl Clone for #name {
170
- #[ inline]
171
- fn clone( & self ) -> Self {
172
- * self
173
- }
174
- }
175
-
176
163
impl #name {
177
164
/// Maximum value the index can take, as a `u32`.
178
165
#vis const MAX_AS_U32 : u32 = #max;
@@ -313,7 +300,6 @@ impl Parse for Newtype {
313
300
314
301
#encodable_impls
315
302
#debug_impl
316
-
317
303
} ) )
318
304
}
319
305
}
0 commit comments