Description
Hello, I was reviewing "An Empirical Study of Rust-for-Linux".
Although Rust has a union primitive, it cannot provide ABI compatibility with C union. Thus RFL implements a struct called
__BindgenUnionField
with the same memory layout as the C interface.
In practice, rust-bindgen can use native unions if using rustc 1.19 or higher. A #[repr(C)] union
is in fact ABI compatible with a C union. The reason for the __BindgenUnionField
workaround is not because of ABI compatibility, but because... I don't know, have people just not read bindgen's documentation? https://rust-lang.github.io/rust-bindgen/using-unions.html?highlight=union#which-union-type-will-bindgen-generate
It only fails to emit them when the type's fields neither implement Copy nor are allowed to use ManuallyDrop
.
I am curious from where you derived the empirical source of your claim?