From: Zhao Liu <[email protected]> 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]> --- rust/migration/src/vmstate.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index f9d9f335b98..595e7e9cd75 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -531,7 +531,11 @@ macro_rules! vmstate_subsections { unsafe impl<T: Sync> Sync for VMStateDescription<T> {} #[derive(Clone)] -pub struct VMStateDescriptionBuilder<T>(bindings::VMStateDescription, PhantomData<fn(&T)>); +pub struct VMStateDescriptionBuilder<T>( + bindings::VMStateDescription, + Option<*const std::os::raw::c_char>, // the name of VMStateDescription + PhantomData<fn(&T)>, +); #[derive(Debug)] pub struct InvalidError; @@ -592,7 +596,7 @@ fn from(_value: InvalidError) -> Errno { impl<T> VMStateDescriptionBuilder<T> { #[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 @@ pub const fn subsections(mut self, subs: &'static VMStateSubsections) -> Self { } #[must_use] - pub const fn build(self) -> VMStateDescription<T> { + pub const fn build(mut self) -> VMStateDescription<T> { + // 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::<T>(self.0, PhantomData) } #[must_use] pub const fn new() -> Self { - Self(bindings::VMStateDescription::ZERO, PhantomData) + Self(bindings::VMStateDescription::ZERO, None, PhantomData) } } -- 2.52.0
