All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org,
	manos.pitsidianakis@linaro.org, shentey@gmail.com
Subject: Re: [PATCH] rust: log: implement io::Write
Date: Tue, 24 Jun 2025 15:21:19 +0800	[thread overview]
Message-ID: <aFpR7+RMBlgt5DTD@intel.com> (raw)
In-Reply-To: <20250617081213.115329-1-pbonzini@redhat.com>

>  /// A macro to log messages conditionally based on a provided mask.
> @@ -24,6 +96,8 @@ pub enum Log {
>  /// log level and, if so, formats and logs the message. It is the Rust
>  /// counterpart of the `qemu_log_mask()` macro in the C implementation.
>  ///
> +/// Errors from writing to the log are ignored.
> +///
>  /// # Parameters
>  ///
>  /// - `$mask`: A log level mask. This should be a variant of the `Log` enum.
> @@ -62,12 +136,9 @@ macro_rules! log_mask_ln {
>          if unsafe {
>              (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
>          } {
> -            let formatted_string = format!("{}\n", format_args!($fmt $($args)*));
> -            let c_string = std::ffi::CString::new(formatted_string).unwrap();
> -
> -            unsafe {
> -                ::qemu_api::bindings::qemu_log(c_string.as_ptr());
> -            }
> +            #[allow(unused_must_use)]

I found this doesn't work :-( :

error: unused `Result` that must be used
   --> ../rust/hw/char/pl011/src/device.rs:281:21
    |
281 |                     log_mask_ln!(Log::Unimp, "pl011: DMA not implemented");
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled
    = note: `-D unused-must-use` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_must_use)]`
    = note: this error originates in the macro `log_mask_ln` (in Nightly builds, run with -Z macro-backtrace for more info)

I understand meson sets `-D warings` so that `allow` can't work...

What about just ignoring the return value? Afterall pl011 doesn't care
the returned value.

@@ -136,8 +137,7 @@ macro_rules! log_mask_ln {
         if unsafe {
             (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
         } {
-            #[allow(unused_must_use)]
-            ::qemu_api::log::LogGuard::log_fmt(
+            let _ = ::qemu_api::log::LogGuard::log_fmt(
                 format_args!("{}\n", format_args!($fmt $($args)*)));
         }
     }};

Thanks,
Zhao

> +            ::qemu_api::log::LogGuard::log_fmt(
> +                format_args!("{}\n", format_args!($fmt $($args)*)));
>          }
>      }};
>  }
> -- 
> 2.49.0
> 
> 


  parent reply	other threads:[~2025-06-24  7:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17  8:12 [PATCH] rust: log: implement io::Write Paolo Bonzini
2025-06-24  6:25 ` Zhao Liu
2025-06-24  7:21 ` Zhao Liu [this message]
2025-06-24  8:22   ` Manos Pitsidianakis
2025-06-24  9:05     ` Zhao Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aFpR7+RMBlgt5DTD@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=shentey@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.