rust: qdev: const_refs_to_static

Now that const_refs_static can be assumed, convert the members of
the DeviceImpl trait from functions to constants.  This lets the
compiler know that they have a 'static lifetime, and removes the
need for the weird "Box::leak()".

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250908105005.2119297-10-pbonzini@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-09-08 12:49:41 +02:00
parent dcdee1e718
commit 2a8a7bb8aa
6 changed files with 33 additions and 55 deletions

View file

@ -1008,16 +1008,11 @@ const VMSTATE_HPET: VMStateDescription<HPETState> =
// SAFETY: HPET_PROPERTIES is a valid Property array constructed with the
// qemu_api::declare_properties macro.
unsafe impl qemu_api::qdev::DevicePropertiesImpl for HPETState {
fn properties() -> &'static [Property] {
&HPET_PROPERTIES
}
const PROPERTIES: &'static [Property] = &HPET_PROPERTIES;
}
impl DeviceImpl for HPETState {
fn vmsd() -> Option<VMStateDescription<Self>> {
Some(VMSTATE_HPET)
}
const VMSTATE: Option<VMStateDescription<Self>> = Some(VMSTATE_HPET);
const REALIZE: Option<fn(&Self) -> qemu_api::Result<()>> = Some(Self::realize);
}