Skip to content

Commit 9607264

Browse files
committed
macros: Work around ctest bugs
Some of our seemingly random failures probably come from this expansion. Work around ctest for now.
1 parent 2a9f3d5 commit 9607264

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/macros.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,30 @@ macro_rules! e {
222222
/// purpose is to calculate the correct enum values.
223223
///
224224
/// See <https://github.com/rust-lang/libc/issues/4419> for more.
225+
// FIXME(ctest): ctest doesn't recognize the `literal` fragment specifier or the `?` kleene. See
226+
// inline comments for how this should be updated once ctest is fixed.
225227
macro_rules! c_enum {
226228
(
227-
$(#[repr($repr:ty)])?
229+
$(#[repr($repr:ty)])* /* ? */
228230
enum $ty_name:ident {
229-
$($variant:ident $(= $value:literal)?,)+
231+
$($variant:ident $(= $value:expr /* literal */)* /* ? */,)+
230232
}
231233
) => {
232-
pub type $ty_name = c_enum!(@ty $($repr)?);
233-
c_enum!(@one; $ty_name; 0; $($variant $(= $value)?,)+);
234+
pub type $ty_name = c_enum!(@ty $($repr)*);
235+
c_enum!(@one; $ty_name; 0; $($variant $(= $value)*,)+);
234236
};
235237

236238
// Matcher for a single variant
237239
(@one; $_ty_name:ident; $_idx:expr;) => {};
238240
(
239241
@one; $ty_name:ident; $default_val:expr;
240-
$variant:ident $(= $value:literal)?,
242+
$variant:ident $(= $value:expr /* literal */)* /* ? */,
241243
$($tail:tt)*
242244
) => {
243245
pub const $variant: $ty_name = {
244246
#[allow(unused_variables)]
245247
let r = $default_val;
246-
$(let r = $value;)?
248+
$(let r = $value;)*
247249
r
248250
};
249251

@@ -254,7 +256,7 @@ macro_rules! c_enum {
254256

255257
// Use a specific type if provided, otherwise default to `c_uint`
256258
(@ty $repr:ty) => { $repr };
257-
(@ty) => { $crate::c_uint };
259+
(@ty) => { /* $ */ crate::c_uint };
258260
}
259261

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

0 commit comments

Comments
 (0)