mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 21:48:02 +00:00
Revamp serde_codegen_internals error handling
This commit is contained in:
@@ -5,8 +5,10 @@ use bound;
|
||||
use internals::ast::{Body, Field, Item, Style, Variant};
|
||||
use internals::{self, attr};
|
||||
|
||||
pub fn expand_derive_serialize(item: &syn::MacroInput) -> Tokens {
|
||||
let item = Item::from_ast(&internals::Ctxt::new(), item);
|
||||
pub fn expand_derive_serialize(item: &syn::MacroInput) -> Result<Tokens, String> {
|
||||
let ctxt = internals::Ctxt::new();
|
||||
let item = Item::from_ast(&ctxt, item);
|
||||
try!(ctxt.check());
|
||||
|
||||
let impl_generics = build_impl_generics(&item);
|
||||
|
||||
@@ -22,7 +24,7 @@ pub fn expand_derive_serialize(item: &syn::MacroInput) -> Tokens {
|
||||
|
||||
let dummy_const = aster::id(format!("_IMPL_SERIALIZE_FOR_{}", item.ident));
|
||||
|
||||
quote! {
|
||||
Ok(quote! {
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const #dummy_const: () = {
|
||||
extern crate serde as _serde;
|
||||
@@ -35,7 +37,7 @@ pub fn expand_derive_serialize(item: &syn::MacroInput) -> Tokens {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// All the generics in the input, plus a bound `T: Serialize` for each generic
|
||||
|
||||
Reference in New Issue
Block a user