mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-30 05:21:55 -06:00

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>
26 lines
675 B
Rust
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(),
|
|
}
|
|
}
|
|
}
|