Skip to content

Commit 9a55522

Browse files
committed
Remove Debug implementation for types where any default impls are UB
This restores buildability with nightly releases after around 2022-04 when it became stricter around unaligned access. Workaround-For: rust-lang/rust-bindgen#2221 See-Also: #3
1 parent e29c391 commit 9a55522

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

build.rs

+33
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,39 @@ fn main() {
181181
.use_core()
182182
.ctypes_prefix("libc")
183183
.impl_debug(true)
184+
// Structs listed here are Packed and thus need impl_debug, but also contain non-Copy
185+
// members.
186+
//
187+
// This is a workaround for <https://github.com/rust-lang/rust-bindgen/issues/2221>; once
188+
// that is fixed and our bindgen is updated, these can just go away again.
189+
//
190+
// If you see any errors like
191+
//
192+
// ```
193+
// error: reference to packed field is unaligned
194+
// --> .../out/bindings.rs:79797:13
195+
// |
196+
// 79797 | self.opcode, self.length, self.data
197+
// | ^^^^^^^^^^^
198+
// |
199+
// = note: `#[deny(unaligned_references)]` on by default
200+
// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
201+
// = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
202+
// = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
203+
// = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
204+
// = note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
205+
// ```
206+
//
207+
// please add the offending struct in here; if existing code depends on the Debug
208+
// implementation, you may add a Debug implementation (that possibly is just a dummy, for
209+
// in these cases it *is* hard to implement showing all details) to this crate for the
210+
// duration of these workarounds.
211+
.no_debug("ble_hci_cmd")
212+
.no_debug("ble_hci_ev_command_complete")
213+
.no_debug("ble_hci_ev_le_subev_big_complete")
214+
.no_debug("ble_hci_ev_le_subev_big_sync_established")
215+
.no_debug("ble_hci_ev_le_subev_periodic_adv_rpt")
216+
.no_debug("ext_adv_report")
184217
.derive_default(true)
185218
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
186219
.generate()

0 commit comments

Comments
 (0)