rust-lang / rust-lang/rust-bindgen
Renamed C++ enums wrapped in namespace produce incorrect variant types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
namespace MyEnum
{
enum Type
{
VALUE = 0,
VALUE2
};
}
Bindgen Invocation
bindgen::Builder::default()
.header("input.h")
.clang_args(&["-x", "c++"])
.parse_callbacks(Box::new(TestCallback))
.generate()
.unwrap();
#[derive(Debug)]
struct TestCallback;
impl ParseCallbacks for TestCallback {
fn item_name(&self, original_item_name: &str) -> Option<String> {
match original_item_name {
"MyEnum_Type" => Some("OtherEnum".into()),
_ => None,
}
}
}
Actual Results
pub const OtherEnum_VALUE: MyEnum_Type = 0;
pub const OtherEnum_VALUE2: MyEnum_Type = 1;
pub type OtherEnum = ::std::os::raw::c_uint;
Expected Results
As you can see above, the variants such as OtherEnum_VALUE are renamed correctly, but the const type is using the old name, which no longer exists. They need to be using the new name of the type. This occurs when using newtype enums as well (did not try rustified enums).
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 by reproducing the bindgen Builder invocation with the provided C++ header and TestCallback::item_name implementation, then trace the generated enum variant declarations and type aliases. Done means renamed enum constants use OtherEnum rather than the obsolete MyEnum_Type, including for newtype enums.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100