Skip to content

Commit 4fea29b

Browse files
committed
smallest change
1 parent 05d89cc commit 4fea29b

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/macros.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,28 @@ macro_rules! e {
218218
/// purpose is to calculate the correct enum values.
219219
///
220220
/// See <https://github.com/rust-lang/libc/issues/4419> for more.
221-
// FIXME(ctest): ctest doesn't like `?` kleenes, `literal` fragments, or `$crate`. See inline
222-
// comments for what eventually should be fixed.
223221
macro_rules! c_enum {
222+
(
223+
$(#[repr($repr:ty)])?
224+
$ty_name:ident {
225+
$($variant:ident $(= $value:expr)?,)+
226+
}
227+
) => {
228+
pub type $ty_name = c_enum!(@ty $($repr)?);
229+
c_enum!(@one; $ty_name; 0; $($variant $(= $value)?,)+);
230+
};
231+
224232
// Matcher for a single variant
225233
(@one; $_ty_name:ident; $_idx:expr;) => {};
226234
(
227235
@one; $ty_name:ident; $default_val:expr;
228-
$variant:ident $(= $value:tt /* literal */)* /* ? */,
236+
$variant:ident $(= $value:expr)?,
229237
$($tail:tt)*
230238
) => {
231239
pub const $variant: $ty_name = {
232240
#[allow(unused_variables)]
233241
let r = $default_val;
234-
$(let r = $value;)*
242+
$(let r = $value;)?
235243
r
236244
};
237245

@@ -241,17 +249,8 @@ macro_rules! c_enum {
241249
};
242250

243251
// Use a specific type if provided, otherwise default to `c_uint`
244-
(@_ty $repr:ty) => { $repr };
245-
(@_ty) => { /* $crate */ crate::c_uint };
246-
(
247-
$(#[repr($repr:ty)])* /* ? */
248-
$ty_name:ident {
249-
$($variant:ident $(= $value:tt /* literal */)* /* ? */,)+
250-
}
251-
) => {
252-
pub type $ty_name = c_enum!(@_ty $($repr)*);
253-
c_enum!(@one; $ty_name; 0; $($variant $(= $value)*,)+);
254-
};
252+
(@ty $repr:ty) => { $repr };
253+
(@ty) => { $crate::c_uint };
255254
}
256255

257256
// This is a pretty horrible hack to allow us to conditionally mark some functions as 'const',

0 commit comments

Comments
 (0)