From: Paolo Bonzini Date: Tue, 28 Oct 2025 11:21:29 +0000 (+0100) Subject: rust: migration: allow passing ParentField<> to vmstate_of! X-Git-Tag: v10.2.0-rc1~40^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4fbf6ff8d12cd11d53f7baa408f50fbb0441d87;p=thirdparty%2Fqemu.git rust: migration: allow passing ParentField<> to vmstate_of! The common superclass for devices could have its own migration state; for it to be included in the subclass's VMState, ParentField<> must implement the VMState trait. Reported-by: Chen Miao Signed-off-by: Paolo Bonzini --- diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 42e5df8d81..5a237c409a 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -268,7 +268,7 @@ macro_rules! impl_vmstate_transparent { ($type:ty where $base:tt: VMState $($where:tt)*) => { unsafe impl<$base> $crate::vmstate::VMState for $type where $base: $crate::vmstate::VMState $($where)* { const BASE: $crate::vmstate::VMStateField = $crate::vmstate::VMStateField { - size: mem::size_of::<$type>(), + size: ::core::mem::size_of::<$type>(), ..<$base as $crate::vmstate::VMState>::BASE }; const VARRAY_FLAG: $crate::bindings::VMStateFlags = <$base as $crate::vmstate::VMState>::VARRAY_FLAG; @@ -282,6 +282,7 @@ impl_vmstate_transparent!(std::cell::Cell where T: VMState); impl_vmstate_transparent!(std::cell::UnsafeCell where T: VMState); impl_vmstate_transparent!(std::pin::Pin where T: VMState); impl_vmstate_transparent!(common::Opaque where T: VMState); +impl_vmstate_transparent!(std::mem::ManuallyDrop where T: VMState); #[macro_export] macro_rules! impl_vmstate_bitsized { diff --git a/rust/qom/src/qom.rs b/rust/qom/src/qom.rs index 5808051cd7..84455cea79 100644 --- a/rust/qom/src/qom.rs +++ b/rust/qom/src/qom.rs @@ -102,7 +102,7 @@ use std::{ }; use common::Opaque; -use migration::impl_vmstate_pointer; +use migration::{impl_vmstate_pointer, impl_vmstate_transparent}; use crate::bindings::{ self, object_class_dynamic_cast, object_dynamic_cast, object_get_class, object_get_typename, @@ -182,6 +182,7 @@ macro_rules! qom_isa { #[derive(Debug)] #[repr(transparent)] pub struct ParentField(std::mem::ManuallyDrop); +impl_vmstate_transparent!(ParentField where T: VMState + ObjectType); impl Deref for ParentField { type Target = T;