mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
rust: assertions: Support index field wrapped in BqlCell
Currently, if the `num` field of a varray is not a numeric type, such as being placed in a wrapper, the array variant of assert_field_type will fail the check. HPET currently wraps num_timers in BqlCell<>. Although BqlCell<> is not necessary from strictly speaking, it makes sense for vmstate to respect BqlCell. The failure of assert_field_type is because it cannot convert BqlCell<T> into usize for use as the index. Use a constant 0 instead for the index, by avoiding $(...)? and extracting the common parts of assert_field_type! into an internal case. Commit message based on a patch by Zhao Liu <zhao1.liu@intel.com>. Link: https://lore.kernel.org/r/20250414144943.1112885-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
756ea88fff
commit
fff99a88be
1 changed files with 9 additions and 16 deletions
|
@ -78,33 +78,26 @@ macro_rules! assert_same_type {
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! assert_field_type {
|
macro_rules! assert_field_type {
|
||||||
($t:ty, $i:tt, $ti:ty) => {
|
(@internal $param_name:ident, $ti:ty, $t:ty, $($field:tt)*) => {
|
||||||
const _: () = {
|
const _: () = {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn assert_field_type(v: $t) {
|
fn assert_field_type($param_name: &$t) {
|
||||||
fn types_must_be_equal<T, U>(_: T)
|
fn types_must_be_equal<T, U>(_: &T)
|
||||||
where
|
where
|
||||||
T: $crate::assertions::EqType<Itself = U>,
|
T: $crate::assertions::EqType<Itself = U>,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
types_must_be_equal::<_, $ti>(v.$i);
|
types_must_be_equal::<_, $ti>(&$($field)*);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
($t:ty, $i:tt, $ti:ty, num = $num:ident) => {
|
($t:ty, $i:tt, $ti:ty) => {
|
||||||
const _: () = {
|
$crate::assert_field_type!(@internal v, $ti, $t, v.$i);
|
||||||
#[allow(unused)]
|
|
||||||
fn assert_field_type(v: $t) {
|
|
||||||
fn types_must_be_equal<T, U>(_: T)
|
|
||||||
where
|
|
||||||
T: $crate::assertions::EqType<Itself = U>,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
let index: usize = v.$num.try_into().unwrap();
|
|
||||||
types_must_be_equal::<_, &$ti>(&v.$i[index]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
($t:ty, $i:tt, $ti:ty, num = $num:ident) => {
|
||||||
|
$crate::assert_field_type!(@internal v, $ti, $t, v.$i[0]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue