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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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