Use parse_macro_input to report parse errors

This commit is contained in:
David Tolnay 2018-09-06 21:14:18 -07:00
parent 27bd640812
commit b49bd52a53
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -81,7 +81,7 @@ mod try;
#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
let input = parse_macro_input!(input as DeriveInput);
ser::expand_derive_serialize(&input)
.unwrap_or_else(compile_error)
.into()
@ -89,7 +89,7 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream {
#[proc_macro_derive(Deserialize, attributes(serde))]
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
let input = parse_macro_input!(input as DeriveInput);
de::expand_derive_deserialize(&input)
.unwrap_or_else(compile_error)
.into()