packed type cannot transitively contain a #[repr(align)] type · Issue #2179 · rust-lang/rust-bindgen (original) (raw)

@ic3man5

Input C/C++ Header

#include <stdint.h>

#pragma pack(push, 2)

typedef struct _UART_SETTINGS { uint16_t Baudrate; uint16_t spbrg; uint16_t brgh; uint16_t parity; uint16_t stop_bits; uint8_t flow_control; /* 0- off, 1 - Simple CTS RTS */ uint8_t reserved_1; union { uint32_t bOptions; struct { unsigned invert_tx : 1; unsigned invert_rx : 1; unsigned half_duplex : 1; unsigned reserved_bits : 13; unsigned reserved_bits2 : 16; } opts; } options; } UART_SETTINGS;

#pragma pack(pop)

Bindgen Invocation

$ bindgen test.h >> test.rs

Actual Results

error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
   --> src\main.rs:149:1
    |
149 | / pub union _UART_SETTINGS__bindgen_ty_1 {
150 | |     pub bOptions: u32,
151 | |     pub opts: _UART_SETTINGS__bindgen_ty_1__bindgen_ty_1,
152 | | }
    | |_^
    |
note: `_UART_SETTINGS__bindgen_ty_1__bindgen_ty_1` has a `#[repr(align)]` attribute
   --> src\main.rs:156:1
    |
156 | / pub struct _UART_SETTINGS__bindgen_ty_1__bindgen_ty_1 {
157 | |     pub _bitfield_align_1: [u8; 0],
158 | |     pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>,
159 | | }
    | |_^

Expected Results

compile successfully. If bitfields are removed and or packed is removed this work.