rust-lang / rust-lang/rust-bindgen

const struct member becomes mut if type not defined

Open
#1,747 1 comment 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.