@@ -233,32 +233,33 @@ macro_rules! e {
233
233
macro_rules! c_enum {
234
234
( $(
235
235
$( #[ repr( $repr: ty) ] ) ?
236
- pub enum $ty_name: ident {
236
+ pub enum $( $ ty_name: ident) ? {
237
237
$( $variant: ident $( = $value: expr) ?, ) +
238
238
}
239
239
) +) => {
240
- $( c_enum!( @expand;
241
- $( #[ repr( $repr) ] ) ?
242
- pub enum $ty_name {
243
- $( $variant $( = $value) ?, ) +
244
- }
245
- ) ; ) +
240
+ $( c_enum!( @expand_repr; $( $repr) ?; $( $ty_name) ?; $( $variant $( = $value) ?, ) +) ; ) +
246
241
} ;
247
242
248
- ( @expand;
249
- $( #[ repr( $repr: ty) ] ) ?
250
- pub enum $ty_name: ident {
251
- $( $variant: ident $( = $value: expr) ?, ) +
252
- }
253
- ) => {
254
- pub type $ty_name = c_enum!( @ty $( $repr) ?) ;
255
- c_enum!( @one; $ty_name; 0 ; $( $variant $( = $value) ?, ) +) ;
243
+ ( @expand_repr; ; $( $ty_name: ident) ?; $( $variants: tt) * ) => {
244
+ // Use a specific type if provided, otherwise default to `CEnumRepr`
245
+ c_enum!( @expand_tyname; $crate:: prelude:: CEnumRepr ; $( $ty_name) ?; $( $variants) * ) ;
246
+ } ;
247
+ ( @expand_repr; $repr: ty; $( $ty_name: ident) ?; $( $variants: tt) * ) => {
248
+ c_enum!( @expand_tyname; $repr; $( $ty_name) ?; $( $variants) * ) ;
249
+ } ;
250
+
251
+ ( @expand_tyname; $repr: ty; ; $( $variants: tt) * ) => {
252
+ c_enum!( @one; $repr; 0 ; $( $variants) * ) ;
253
+ } ;
254
+ ( @expand_tyname; $repr: ty; $ty_name: ident; $( $variants: tt) * ) => {
255
+ pub type $ty_name = $repr;
256
+ c_enum!( @one; $ty_name; 0 ; $( $variants) * ) ;
256
257
} ;
257
258
258
259
// Matcher for a single variant
259
- ( @one; $_ty_name: ident ; $_idx: expr; ) => { } ;
260
+ ( @one; $_ty_name: ty ; $_idx: expr; ) => { } ;
260
261
(
261
- @one; $ty_name: ident ; $default_val: expr;
262
+ @one; $ty_name: ty ; $default_val: expr;
262
263
$variant: ident $( = $value: expr) ?,
263
264
$( $tail: tt) *
264
265
) => {
@@ -273,10 +274,6 @@ macro_rules! c_enum {
273
274
// set explicitly.
274
275
c_enum!( @one; $ty_name; $variant + 1 ; $( $tail) * ) ;
275
276
} ;
276
-
277
- // Use a specific type if provided, otherwise default to `CEnumRepr`
278
- ( @ty $repr: ty) => { $repr } ;
279
- ( @ty) => { $crate:: prelude:: CEnumRepr } ;
280
277
}
281
278
282
279
// This is a pretty horrible hack to allow us to conditionally mark some functions as 'const',
@@ -449,7 +446,7 @@ mod tests {
449
446
// C enums always take one more than the previous value, unless set to a specific
450
447
// value. Duplicates are allowed.
451
448
c_enum ! {
452
- pub enum e {
449
+ pub enum {
453
450
VAR0 ,
454
451
VAR2_0 = 2 ,
455
452
VAR3_0 ,
0 commit comments