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
+4 -3
View File
@@ -5,11 +5,12 @@ use bound;
use internals::ast::{Body, Field, Item, Style, Variant};
use internals::{self, attr};
pub fn expand_derive_deserialize(item: &syn::MacroInput) -> Tokens {
pub fn expand_derive_deserialize(item: &syn::MacroInput) -> Result<Tokens, String> {
let item = {
let ctxt = internals::Ctxt::new();
let item = Item::from_ast(&ctxt, item);
check_no_str(&ctxt, &item);
try!(ctxt.check());
item
};
@@ -27,7 +28,7 @@ pub fn expand_derive_deserialize(item: &syn::MacroInput) -> Tokens {
let dummy_const = aster::id(format!("_IMPL_DESERIALIZE_FOR_{}", item.ident));
quote! {
Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
extern crate serde as _serde;
@@ -40,7 +41,7 @@ pub fn expand_derive_deserialize(item: &syn::MacroInput) -> Tokens {
}
}
};
}
})
}
// All the generics in the input, plus a bound `T: Deserialize` for each generic