On Thu, Jun 05, 2025 at 12:11:22PM +0200, Paolo Bonzini wrote: > Date: Thu, 5 Jun 2025 12:11:22 +0200 > From: Paolo Bonzini <pbonz...@redhat.com> > Subject: [PATCH 1/3] rust: make TryFrom macro more resilient > X-Mailer: git-send-email 2.49.0 > > If the enum includes values such as "Ok", "Err", or "Error", the TryInto > macro can cause errors. Be careful and qualify identifiers with the full > path, or in the case of TryFrom<>::Error do not use the associated type > at all. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > rust/qemu-api-macros/src/lib.rs | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-)
Though I'm late... Reviewed-by: Zhao Liu <zhao1....@intel.com> > diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs > index 103470785e3..c18bb4e036f 100644 > --- a/rust/qemu-api-macros/src/lib.rs > +++ b/rust/qemu-api-macros/src/lib.rs > @@ -203,8 +203,8 @@ fn derive_tryinto_body( > Ok(quote! { > #(const #discriminants: #repr = #name::#discriminants as #repr;)*; > match value { > - #(#discriminants => Ok(#name::#discriminants),)* > - _ => Err(value), > + #(#discriminants => > core::result::Result::Ok(#name::#discriminants),)* > + _ => core::result::Result::Err(value), error.rs is using std::result, so I think it's better to use std rather than core if possible. But there are many other cases like this where std and core are mixed, maybe we can clean it up to always prefer the std.