Skip to content

Commit

Permalink
Allow anonymous enums to be formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 14, 2023
1 parent 1c75f1a commit d74e1c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,11 @@ impl fmt::Display for Stmt {
writeln!(f, "{macro_name}!(")?;
writeln!(f, " #[underlying({ty})]")?;
write!(f, "{availability}")?;
write!(f, " pub enum ",)?;
if let Some(name) = &id.name {
write!(f, "{name} ")?;
}
writeln!(f, "{{")?;
writeln!(
f,
" pub enum {} {{",
id.name.as_deref().unwrap_or("__anonymous__")
)?;
for (name, availability, expr) in variants {
write!(f, "{availability}")?;
writeln!(f, " {name} = {expr},")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/icrate/src/generated
16 changes: 8 additions & 8 deletions crates/icrate/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ macro_rules! extern_enum {
(
#[underlying($ty:ty)]
$(#[$m:meta])*
$v:vis enum $name:ident {
$v:vis enum __anonymous__ {
$(
$(#[$field_m:meta])*
$field:ident = $value:expr
),* $(,)?
}
) => {
// TODO: Improve type-safety
$(#[$m])*
$v type $name = $ty;

extern_enum! {
@__inner
@($v)
@($name)
@($ty)
@($(
$(#[$field_m])*
$field = $value,
Expand All @@ -64,17 +60,21 @@ macro_rules! extern_enum {
(
#[underlying($ty:ty)]
$(#[$m:meta])*
$v:vis enum {
$v:vis enum $name:ident {
$(
$(#[$field_m:meta])*
$field:ident = $value:expr
),* $(,)?
}
) => {
// TODO: Improve type-safety
$(#[$m])*
$v type $name = $ty;

extern_enum! {
@__inner
@($v)
@($ty)
@($name)
@($(
$(#[$field_m])*
$field = $value,
Expand Down

0 comments on commit d74e1c5

Please sign in to comment.