Skip to content
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

Enums initialized with other enum constants don't take renaming into account #999

Open
jsgf opened this issue Sep 5, 2024 · 0 comments
Open

Comments

@jsgf
Copy link

jsgf commented Sep 5, 2024

Given the Rust file foo.rs:

#[repr(u32)]
pub enum A {
    Apple = 1,
    Pear = 2,
    Banana = 3,
}

#[repr(u32)]
pub enum B {
    A = A::Apple as u32,
    B = A::Pear as u32,
    C = A::Banana as u32,
}

and the cbindgen.toml config

language = "C"
cpp_compat = false

[export]
include = ["A", "B"]
item_types = ["enums"]

[enum]
rename_variants = "QualifiedScreamingSnakeCase"

The command cbindgen -c cbindgen.toml foo.rs generates:

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

enum A {
  A_APPLE = 1,
  A_PEAR = 2,
  A_BANANA = 3,
};
typedef uint32_t A;

enum B {
  B_A = (uint32_t)A_Apple,
  B_B = (uint32_t)A_Pear,
  B_C = (uint32_t)A_Banana,
};
typedef uint32_t B;

Note that B_A is initialized from A_Apple rather than A_APPLE, ignoring the rename_variants = "QualifiedScreamingSnakeCase" config option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant