Skip to contentSkip to conversation

rust: Fix compilation with rustc v1.88

PATCH In review Bernhard Beschow 2 participants 3 messages Jul 8, 2025 – Jul 9, 2025 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: Fix compilation with rustc v1.88

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.

---
 rust/qemu-api/src/bindings.rs | 1 +
 1 file changed, 1 insertion(+)
rust/qemu-api/src/bindings.rs +1 -0
index 057de4b646..3cdad0f0ec 100644
@@ -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,
Signature · 1 line
2.50.0