rust-lang / rust-lang/rust-bindgen

The enum_name argument for enum_variant_name fn of ParseCallbacks trait includes the enum keyword along with the name

Open
#3,113 4 comments 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

If I run the following code with bindgen version 0.71.1 (latest as of this moment):

fn main() {
    let code = r"
        typedef enum MyEnum {
            MyEnumVariantA,
            MyEnumVariantB,
        } MyEnum;
    ";
    #[derive(Debug)]
    struct ParseCb;
    impl bindgen::callbacks::ParseCallbacks for ParseCb {
        fn enum_variant_name(
            &self,
            enum_name: Option<&str>,
            _original_variant_name: &str,
            _variant_value: bindgen::callbacks::EnumVariantValue,
        ) -> Option<String> {
            dbg!(enum_name);
            None
        }
    }
    bindgen::builder()
        .parse_callbacks(Box::new(ParseCb))
        .header_contents("temp.h", code)
        .generate()
        .unwrap();
}

I get this output:

[src/main.rs:17:13] enum_name = Some(
    "enum MyEnum",
)
[src/main.rs:17:13] enum_name = Some(
    "enum MyEnum",
)

We should only get the MyEnum part. If this is not a bug, then, it should at least be documented in the function docs.

Temporary workaround: just do enum_name.strip_prefix("enum ") (note the space after the enum keyword).

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 at the ParseCallbacks::enum_variant_name entry point and reproduce the issue with the provided header_contents example. Trace how the enum name is passed to the callback, then verify that the callback receives only MyEnum or that the function documentation clearly describes the existing value.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.