On Tue, Oct 15, 2024 at 03:17:21PM +0200, Paolo Bonzini wrote:
> Date: Tue, 15 Oct 2024 15:17:21 +0200
> From: Paolo Bonzini <pbonz...@redhat.com>
> Subject: [PATCH 03/16] rust: pass rustc_args when building all crates
> X-Mailer: git-send-email 2.46.2
> 
> rustc_args is needed to smooth the difference in warnings between the various
> versions of rustc.  Always include those arguments.
> 
> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
> ---
>  meson.build                       | 18 +++++++++++-------
>  rust/qemu-api/meson.build         |  2 +-
>  rust/qemu-api/src/device_class.rs | 10 ++++++----
>  3 files changed, 18 insertions(+), 12 deletions(-)

LGTM (with one trivial comment inline)

Reviewed-by: Zhao Liu <zhao1....@intel.com>

> diff --git a/rust/qemu-api/src/device_class.rs 
> b/rust/qemu-api/src/device_class.rs
> index 1ea95beb78d..b6b68cf9ce2 100644
> --- a/rust/qemu-api/src/device_class.rs
> +++ b/rust/qemu-api/src/device_class.rs
> @@ -16,10 +16,12 @@ macro_rules! device_class_init {
>          ) {
>              let mut dc =
>                  
> ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap();
> -            dc.as_mut().realize = $realize_fn;
> -            dc.as_mut().vmsd = &$vmsd;
> -            $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), 
> $legacy_reset_fn);
> -            $crate::bindings::device_class_set_props(dc.as_mut(), 
> $props.as_mut_ptr());
> +            unsafe {
> +                dc.as_mut().realize = $realize_fn;
> +                dc.as_mut().vmsd = &$vmsd;
> +                $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), 
> $legacy_reset_fn);
> +                $crate::bindings::device_class_set_props(dc.as_mut(), 
> $props.as_mut_ptr());
> +            }

The issue exists because the unsafe_op_in_unsafe_fn is allowed in
rust/qemu-api/src/lib.rs. So should we wrap the bindings in a separate
lib (similar to the rust/bindings in the Linux kernel)?

This way, the special lint settings can be applied only to the binding
files, while the default lint checks can cover the other user
development code.

In addition, another thing that confuses me is why bindgen still
generates code that does not follow the unsafe_op_in_unsafe_fn
requirement. It seems that bindgen has supported unsafe_op_in_unsafe_fn
since v0.62 [1, 2], but binding code we generated still violates
unsafe_op_in_unsafe_fn. Is this a bug of bindgen?

[1]: https://github.com/rust-lang/rust-bindgen/pull/2266 
[2]: https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md#changed-12

Regards,
Zhao



Reply via email to