rust-lang / rust-lang/rust-bindgen
const struct member becomes mut if type not defined
Open
Nobody has claimed this yet.
bug
help wanted
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
// Comment out this to turn *mut b -> *const b in generated Rust code.
#define BUG
#if !defined(BUG)
struct b;
#endif
struct a {
const struct b *x;
};
Bindgen Invocation
$ bindgen input.h --no-layout-tests
Actual Results
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct a {
pub x: *mut b,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct b {
pub _address: u8,
}
Expected Results
The struct member becomes const/mut depending on if it's defined or not.
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 running bindgen input.h --no-layout-tests with the provided header, both with BUG defined and with struct b declared. Compare the generated Rust pointer mutability; the fix is complete when the member is const or mut according to whether struct b is defined, without changing the other generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100