Revamp serde_codegen_internals error handling

This commit is contained in:
David Tolnay
2016-09-27 00:11:37 -07:00
parent 4ad6c4fd56
commit 0c18c151e2
5 changed files with 54 additions and 27 deletions
+6 -4
View File
@@ -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