Rustc v1.88 ships with a new lint `unnecessary_transmutes` which triggers the
following error when compiling code generated by bindgen:
error: unnecessary transmute
--> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:792:18
|
792 | unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace this with: `u32::cast_signed(self._bitfield_1.get(0usize, 24u8) as u32)`
|
= note: `-D unnecessary-transmutes` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unnecessary_transmutes)]`
error: unnecessary transmute
--> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:797:28
|
797 | let val: u32 = ::std::mem::transmute(val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace this with: `i32::cast_unsigned(val)`
error: unnecessary transmute
--> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:804:13
|
804 | / ::std::mem::transmute(<__BindgenBitfieldUnit<[u8; 3usize]>>::raw_get(
805 | | ::std::ptr::addr_of!((*this)._bitfield_1),
806 | | 0usize,
807 | | 24u8,
808 | | ) as u32)
| |_____________________^
|
help: replace this with
|
804 ~ u32::cast_signed(<__BindgenBitfieldUnit<[u8; 3usize]>>::raw_get(
805 + ::std::ptr::addr_of!((*this)._bitfield_1),
806 + 0usize,
807 + 24u8,
808 + ) as u32)
|
error: unnecessary transmute
--> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:814:28
|
814 | let val: u32 = ::std::mem::transmute(val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace this with: `i32::cast_unsigned(val)`
error: unnecessary transmute
--> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:827:41
|
827 | let _flags2: u32 = unsafe { ::std::mem::transmute(_flags2) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace this with: `i32::cast_unsigned(_flags2)`
error: aborting due to 5 previous errors
Silence the lint in the generated code by adding it to the allow list.
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
rust/qemu-api/src/bindings.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs
index 057de4b646..3cdad0f0ec 100644
--- a/rust/qemu-api/src/bindings.rs
+++ b/rust/qemu-api/src/bindings.rs
@@ -6,6 +6,7 @@
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
+ unnecessary_transmutes,
unsafe_op_in_unsafe_fn,
clippy::pedantic,
clippy::restriction,
--
2.50.0
Hi Bernhard, Thanks for your patch! There was an identical patch last week on the list: https://lore.kernel.org/qemu-rust/20250703-rust_bindings_allow_unnecessary_transmutes-v1-1-692ca210d331@linaro.org/ -- Manos Pitsidianakis Emulation and Virtualization Engineer at Linaro Ltd
Am 9. Juli 2025 06:22:11 UTC schrieb Manos Pitsidianakis <manos.pitsidianakis@linaro.org>: >Hi Bernhard, > >Thanks for your patch! > >There was an identical patch last week on the list: >https://lore.kernel.org/qemu-rust/20250703-rust_bindings_allow_unnecessary_transmutes-v1-1-692ca210d331@linaro.org/ > Oh, I missed it. I just added my r-b. Thanks, Bernhard
© 2016 - 2025 Red Hat, Inc.