rust-lang / rust-lang/rust-bindgen

Use field name instead of bindgen_ty_1

Open
#2,000 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Hi!

This is related to #1971 but not exactly the same. In my case, the unions and structs are named by their field, so it would be nice if bindgen could make use of that name.

Since I saw that the other issue was "help wanted" I spend some time trying to figure it out, but with all complex type parsing code I couldn't understand how to link the resolved type to the field name.

Input C/C++ Header
struct snd_ctl_event {
	int type;
	union {
		struct {
			unsigned int mask;
			struct snd_ctl_elem_id id;
		} elem;
		unsigned char data8[60];
	} data;
};
Actual Results
pub struct snd_ctl_event__bindgen_ty_1__bindgen_ty_1 {
    pub mask: c_uint,
    pub id: snd_ctl_elem_id,
}

pub union snd_ctl_event__bindgen_ty_1 {
    pub elem: snd_ctl_event__bindgen_ty_1__bindgen_ty_1,
    pub data8: [c_uchar; 60],
    // some fields omitted
}
// etc
Expected Results
pub struct snd_ctl_event__data__elem {
    pub mask: c_uint,
    pub id: snd_ctl_elem_id,
}

pub union snd_ctl_event__data {
    pub elem: snd_ctl_event__data__elem,
    pub data8: [c_uchar; 60],
    // some fields omitted
}
// etc

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 with bindgen's complex type parsing code and compare this issue with related issue #1971. Trace how anonymous unions and structs are linked to their fields; done means generated names use the field path, such as snd_ctl_event__data and snd_ctl_event__data__elem, instead of bindgen_ty_1.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.