Skip to content

macros: Work around ctest bugs #4469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,28 +222,30 @@ macro_rules! e {
/// purpose is to calculate the correct enum values.
///
/// See <https://github.com/rust-lang/libc/issues/4419> 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
};

Expand All @@ -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',
Expand Down
Loading