rust-lang / rust-lang/rust-bindgen

Unable to rename enums

Open
#3,154 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

I have an enum like this in C:

enum SHType : uint8_t {
  None,
  Any,
  Enum,
  Bool,
  ...
}

Turns into:

pub const SHType_None: SHType = 0;
pub const SHType_Any: SHType = 1;
pub const SHType_Enum: SHType = 2;
pub const SHType_Bool: SHType = 3;
...
pub type SHType = u8;

Which when used inside match blocks will generate:

warning: constant in pattern `SHType_Float3` should have an upper case name
   --> src\widgets\var_util.rs:194:9
    |
194 |         SHType_Float3 => {
    |         ^^^^^^^^^^^^^ help: convert the identifier to upper case: `SHTYPE_FLOAT3`

I have tried to use ParseCallbacks with enum_variant_name to rename the enum, but it only works on the variant part, not the type (turns into SHType_FLOAT3, instead of SHTYPE_FLOAT3)
I also tried to use item_name in addition which kind of works except it renames the actual type also to SHTYPE, which I want to keep regular, I just want to rename the constants. Anything I'm missing in bindgen that can do this or is it just something that is not possible yet?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ParseCallbacks::enum_variant_name and item_name, using the shown SHType example to see how each callback affects enum variants, constants, and the generated type name. Done means the constants can receive the requested uppercase names while the SHType type remains unchanged, with the generated bindings compiling without the reported naming warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.