From 9607264700bd2c3994fdff3d771884224001c5be Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 2 Jun 2025 00:33:37 +0000 Subject: [PATCH] macros: Work around ctest bugs Some of our seemingly random failures probably come from this expansion. Work around ctest for now. --- src/macros.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 6b5f403fdfb1..0f1e3e8f6cc9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -222,28 +222,30 @@ macro_rules! e { /// purpose is to calculate the correct enum values. /// /// See for more. +// FIXME(ctest): ctest doesn't recognize the `literal` fragment specifier or the `?` kleene. See +// inline comments for how this should be updated once ctest is fixed. macro_rules! c_enum { ( - $(#[repr($repr:ty)])? + $(#[repr($repr:ty)])* /* ? */ enum $ty_name:ident { - $($variant:ident $(= $value:literal)?,)+ + $($variant:ident $(= $value:expr /* literal */)* /* ? */,)+ } ) => { - pub type $ty_name = c_enum!(@ty $($repr)?); - c_enum!(@one; $ty_name; 0; $($variant $(= $value)?,)+); + pub type $ty_name = c_enum!(@ty $($repr)*); + c_enum!(@one; $ty_name; 0; $($variant $(= $value)*,)+); }; // Matcher for a single variant (@one; $_ty_name:ident; $_idx:expr;) => {}; ( @one; $ty_name:ident; $default_val:expr; - $variant:ident $(= $value:literal)?, + $variant:ident $(= $value:expr /* literal */)* /* ? */, $($tail:tt)* ) => { pub const $variant: $ty_name = { #[allow(unused_variables)] let r = $default_val; - $(let r = $value;)? + $(let r = $value;)* r }; @@ -254,7 +256,7 @@ macro_rules! c_enum { // Use a specific type if provided, otherwise default to `c_uint` (@ty $repr:ty) => { $repr }; - (@ty) => { $crate::c_uint }; + (@ty) => { /* $ */ crate::c_uint }; } // This is a pretty horrible hack to allow us to conditionally mark some functions as 'const',