Skip to content

Commit 55bc2b1

Browse files
committed
Fixes alignment errors with new Rust union type
This fix creates a new private field with the required aligned size. This new private field ensures that the union has the required size.
1 parent fdee9f1 commit 55bc2b1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/codegen/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,14 +1600,20 @@ impl CodeGenerator for CompInfo {
16001600
);
16011601
}
16021602

1603-
if is_union && !ctx.options().unstable_rust {
1603+
if is_union {
16041604
let layout = layout.expect("Unable to get layout information?");
16051605
let ty = BlobTyBuilder::new(layout).build();
1606-
let field = StructFieldBuilder::named("bindgen_union_field")
1607-
.pub_()
1608-
.build_ty(ty);
1606+
1607+
let field = if ctx.options().unstable_rust {
1608+
StructFieldBuilder::named("_bindgen_union_align")
1609+
.build_ty(ty)
1610+
} else {
1611+
struct_layout.saw_union(layout);
16091612

1610-
struct_layout.saw_union(layout);
1613+
StructFieldBuilder::named("bindgen_union_field")
1614+
.pub_()
1615+
.build_ty(ty)
1616+
};
16111617

16121618
fields.push(field);
16131619
}

0 commit comments

Comments
 (0)