Skip to content

Commit e5ec1ab

Browse files
committed
Add the enum keyword to the c_enum macro
Our `style.sh` script can't handle these easily, and it seems like `ctest` may struggle with this macro. Add the `enum` keyword so the expanded code is valid Rust. (backport <#4494>) (cherry picked from commit 19e04c8)
1 parent f0e2ab1 commit e5ec1ab

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

ci/style.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while IFS= read -r file; do
2626

2727
# Turn all braced macro `foo! { /* ... */ }` invocations into
2828
# `fn foo_fmt_tmp() { /* ... */ }`.
29-
perl -pi -e 's/(?!macro_rules|c_enum)\b(\w+)!\s*\{/fn $1_fmt_tmp() {/g' "$file"
29+
perl -pi -e 's/(?!macro_rules)\b(\w+)!\s*\{/fn $1_fmt_tmp() {/g' "$file"
3030

3131
# Replace `if #[cfg(...)]` within `cfg_if` with `if cfg_tmp!([...])` which
3232
# `rustfmt` will format. We put brackets within the parens so it is easy to

src/macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ macro_rules! e {
223223
macro_rules! c_enum {
224224
(
225225
$(#[repr($repr:ty)])?
226-
$ty_name:ident {
226+
enum $ty_name:ident {
227227
$($variant:ident $(= $value:literal)?,)+
228228
}
229229
) => {
@@ -411,7 +411,7 @@ mod tests {
411411
fn c_enumbasic() {
412412
// By default, variants get sequential values.
413413
c_enum! {
414-
e {
414+
enum e {
415415
VAR0,
416416
VAR1,
417417
VAR2,
@@ -428,7 +428,7 @@ mod tests {
428428
// By default, variants get sequential values.
429429
c_enum! {
430430
#[repr(u16)]
431-
e {
431+
enum e {
432432
VAR0,
433433
}
434434
}
@@ -440,7 +440,7 @@ mod tests {
440440
fn c_enumset_value() {
441441
// Setting an explicit value resets the count.
442442
c_enum! {
443-
e {
443+
enum e {
444444
VAR2 = 2,
445445
VAR3,
446446
VAR4,
@@ -457,7 +457,7 @@ mod tests {
457457
// C enums always take one more than the previous value, unless set to a specific
458458
// value. Duplicates are allowed.
459459
c_enum! {
460-
e {
460+
enum e {
461461
VAR0,
462462
VAR2_0 = 2,
463463
VAR3_0,

src/unix/linux_like/linux/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ e! {
9595
}
9696

9797
c_enum! {
98-
pid_type {
98+
enum pid_type {
9999
PIDTYPE_PID,
100100
PIDTYPE_TGID,
101101
PIDTYPE_PGID,
@@ -4559,14 +4559,14 @@ pub const RTNLGRP_STATS: c_uint = 0x24;
45594559

45604560
// linux/cn_proc.h
45614561
c_enum! {
4562-
proc_cn_mcast_op {
4562+
enum proc_cn_mcast_op {
45634563
PROC_CN_MCAST_LISTEN = 1,
45644564
PROC_CN_MCAST_IGNORE = 2,
45654565
}
45664566
}
45674567

45684568
c_enum! {
4569-
proc_cn_event {
4569+
enum proc_cn_event {
45704570
PROC_EVENT_NONE = 0x00000000,
45714571
PROC_EVENT_FORK = 0x00000001,
45724572
PROC_EVENT_EXEC = 0x00000002,

0 commit comments

Comments
 (0)