qemu/rust/qemu-api-macros/src/utils.rs
Paolo Bonzini a3b620fff7 rust: qemu-api-macros: extend error reporting facility to parse errors
Generalize the CompileError tuple to an enum, that can be either an error
message or a parse error from syn.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-01-10 23:34:43 +01:00

26 lines
675 B
Rust

// Procedural macro utilities.
// Author(s): Paolo Bonzini <pbonzini@redhat.com>
// SPDX-License-Identifier: GPL-2.0-or-later
use proc_macro2::Span;
use quote::quote_spanned;
pub enum MacroError {
Message(String, Span),
ParseError(syn::Error),
}
impl From<syn::Error> for MacroError {
fn from(err: syn::Error) -> Self {
MacroError::ParseError(err)
}
}
impl From<MacroError> for proc_macro2::TokenStream {
fn from(err: MacroError) -> Self {
match err {
MacroError::Message(msg, span) => quote_spanned! { span => compile_error!(#msg); },
MacroError::ParseError(err) => err.into_compile_error(),
}
}
}