[Feature request] non_exhaustive structs
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
The issue names no files or tests. Start by locating bindgen's struct-generation and configuration paths, then inspect how repr(C), Default, and other generated attributes are handled. Done means an optional setting can apply non_exhaustive to all or selected structs, with the layout and C-compatibility trade-offs covered by tests.
Written by the indexing model from the issue text.
Description
From a C API point of view, adding a field to a struct is often not seen as a breaking change, for fields that are not mentioned when giving a struct by value are zeroed. The Rust equivalent would be to make all structs non_exhaustive (which, unless the type is not supposed to be constructed from Rust, only makes sense if Default is derived on it).
Therefore, I think it would make sense to enable having non_exhaustive on structs, so that more C non-breaking changes can be translated to Rust non-breaking changes. A -sys crate using this would merely need to make the decision of whether either
- the underlying C library only adds fields at the end (or in alignment-guaranteed gaps), or
- the -sys crate makes the concession that the
#[repr(C)]merely guarantees that it is aligned with the linked C code, but no concrete layout guarantee.
Is this something that you agree would make sense to have in bindgen (say, as an optional "make all (or selected) structs non_exhaustive")? Is there anything that a PR implementing this could do to make 2. go over better? (I don't think we can make the repr property non-pub, but maybe there are tricks I'm missing.)
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 846
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from rust-lang/rust-bindgen
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)Possibly taken @lwz23 claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
rust-lang/rust-bindgen#3485 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-bindgen#3483 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
rust-lang/rust-bindgen#3370 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rust-lang/rust-bindgen#3363 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rust-lang/rust-bindgen#3540 ·
Maintainers usually reply within 1 day
All issues in rust-lang/rust-bindgen
Similar issues
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day
-
area:models enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day