mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-03 15:32:26 -06:00
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>
This commit is contained in:
parent
22a18f0a98
commit
a3b620fff7
2 changed files with 36 additions and 17 deletions
26
rust/qemu-api-macros/src/utils.rs
Normal file
26
rust/qemu-api-macros/src/utils.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
// 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(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue