rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Support repr(C) for rustified enums

Open thedataking opened this issue 4 months ago • 3 comments

TODOs:

  • [ ] check enum width as suggested by @emilio in this comment
  • [ ] should there be a --rustified-non-exhaustive-repr-c-enum flag?
  • [x] Update CHANGELOG.md

Closes #3263.

thedataking avatar Aug 14 '25 07:08 thedataking

At the very least we should add a big warning on this option since it'd cause wrong struct layout.

I agree this would be good. However, it appears that LLVM does not expose the necessary APIs. Even if we exposed the necessary functionality, it would presumably only work for recent clang versions. Thoughts on how to proceed?

thedataking avatar Aug 21 '25 10:08 thedataking

What do you think of extending our layout tests to test the layout of enums? I think at least that would signal that there's something wrong with the generated code if you misuse this option.

Other than that it looks good.

emilio avatar Oct 18 '25 08:10 emilio

Our repr(C) layout is actually very likely to be incorrect for many enums and we are considering how to deprecate it because it is very hard to address this.

workingjubilee avatar Oct 29 '25 04:10 workingjubilee