From: Zhao Liu Date: Thu, 13 Nov 2025 05:19:18 +0000 (+0800) Subject: rust/migration: Check name field in VMStateDescriptionBuilder X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=febdab3d5de155fb526d4237493ee4234f6005e1;p=thirdparty%2Fqemu.git rust/migration: Check name field in VMStateDescriptionBuilder The name field is necessary for VMStateDescription, so that it's necessary to check if it is set when build VMStateDescription. Since is_null()/as_ref() become rustc v1.84 and pointer cannot cast to integer in const, use Option<> to check name with a new field in VMStateDescriptionBuilder instead. This can be simplified in future when QEMU bumps up rustc version. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20251113051937.4017675-4-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index f9d9f335b9..595e7e9cd7 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -531,7 +531,11 @@ pub struct VMStateDescription(bindings::VMStateDescription, PhantomData Sync for VMStateDescription {} #[derive(Clone)] -pub struct VMStateDescriptionBuilder(bindings::VMStateDescription, PhantomData); +pub struct VMStateDescriptionBuilder( + bindings::VMStateDescription, + Option<*const std::os::raw::c_char>, // the name of VMStateDescription + PhantomData, +); #[derive(Debug)] pub struct InvalidError; @@ -592,7 +596,7 @@ unsafe extern "C" fn vmstate_dev_unplug_pending_cb FnCall<(&'a T,) impl VMStateDescriptionBuilder { #[must_use] pub const fn name(mut self, name_str: &CStr) -> Self { - self.0.name = ::std::ffi::CStr::as_ptr(name_str); + self.1 = Some(::std::ffi::CStr::as_ptr(name_str)); self } @@ -718,13 +722,16 @@ impl VMStateDescriptionBuilder { } #[must_use] - pub const fn build(self) -> VMStateDescription { + pub const fn build(mut self) -> VMStateDescription { + // FIXME: is_null()/as_ref() become const since v1.84. + assert!(self.1.is_some(), "VMStateDescription requires name field!"); + self.0.name = self.1.unwrap(); VMStateDescription::(self.0, PhantomData) } #[must_use] pub const fn new() -> Self { - Self(bindings::VMStateDescription::ZERO, PhantomData) + Self(bindings::VMStateDescription::ZERO, None, PhantomData) } }