qemu-cr16/rust
Paolo Bonzini 8999ca00a4 rust: migration: extract vmstate_fields_ref
This is useful when building a VMState for generic structs, because you have
to avoid nested statics.  Using vmstate_fields! will fail in the likely case
where the _FIELDS static uses Self from an outer item, because that is
forbidden.

The separate macros are needed because you cannot just do

                 .fields(vmstate_fields_ref! {
                      vmstate_of!(PL011State, clock),
                 })

The value returned by vmstate_fields_ref! is not promoted to static, which is
unfortunate but intentional (https://github.com/rust-lang/rust/issues/60502):

error[E0716]: temporary value dropped while borrowed
   --> rust/hw/char/pl011/libpl011.rlib.p/structured/device.rs:743:17
    |
738 | /      VMStateDescriptionBuilder::<PL011State>::new()
739 | |          .name(c"pl011/clock")
740 | |          .version_id(1)
741 | |          .minimum_version_id(1)
742 | |          .needed(&PL011State::clock_needed)
743 | |          .fields(vmstate_fields_ref! {
    | | _________________^
744 | ||              vmstate_of!(PL011State, clock),
745 | ||         })
    | ||_________^- argument requires that borrow lasts for `'static`
    |  |_________|
    |            creates a temporary value which is freed while still in use
746 |            .build();
    |                   - temporary value is freed at the end of this statement

Thus it is necessary to use the "static", whether explicitly or hidden by
vmstate_fields.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-14 11:03:59 +02:00
..
bindings/src rust: split "hwcore" crate 2025-09-17 19:00:57 +02:00
bits rust: re-export qemu_macros internal helper in "bits" 2025-09-17 19:00:57 +02:00
bql rust: bql: add BqlRefCell::get_mut() 2025-10-14 11:03:59 +02:00
chardev rust: use glib-sys 2025-10-03 15:14:48 +02:00
common rust/common/uninit: Fix Clippy's complaints about lifetime 2025-09-22 17:17:18 +02:00
hw rust: hpet: fix fw_cfg handling 2025-10-14 11:03:43 +02:00
migration rust: migration: extract vmstate_fields_ref 2025-10-14 11:03:59 +02:00
qemu-macros rust: bits: disable double_parens check 2025-10-14 01:44:41 +02:00
qom rust: use glib-sys 2025-10-03 15:14:48 +02:00
system rust: use glib-sys 2025-10-03 15:14:48 +02:00
tests rust: re-export qemu macros from common/qom/hwcore 2025-09-17 19:00:58 +02:00
trace tracetool/syslog: add Rust support 2025-10-01 11:22:07 -04:00
util rust: use glib-sys 2025-10-03 15:14:48 +02:00
.gitignore
Cargo.lock rust: use glib-sys 2025-10-03 15:14:48 +02:00
Cargo.toml rust: use glib-sys 2025-10-03 15:14:48 +02:00
Kconfig rust: add PL011 device model 2024-11-05 14:18:15 +01:00
meson.build subprojects: add glib-sys-rs 2025-10-03 15:14:48 +02:00
rustfmt.toml rust: add crate to expose bindings and interfaces 2024-10-11 12:32:17 +02:00