rust-lang / rust-lang/rust-bindgen
Invalid code generated when a struct contains fields called `type` and `type_`
Open
Nobody has claimed this yet.
bug
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Header to reproduce:
typedef struct foo {
int type;
int type_;
};
The resulting code will be:
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
pub type_: ::std::os::raw::c_int,
pub type_: ::std::os::raw::c_int,
}
Which is of course, invalid. It would probably make sense to at least give an error rather than generating invalid code here.
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 with the C header in the issue and reproduce the generated Rust binding containing duplicate type_ fields. Trace the name-conversion and collision handling used during binding generation. Done means the input no longer produces invalid Rust, either by generating distinct identifiers or by reporting a clear error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100