Merge pull request #564 from serde-rs/cleanup

Clean up syn workarounds
This commit is contained in:
David Tolnay
2016-09-28 09:48:45 -07:00
committed by GitHub
2 changed files with 26 additions and 43 deletions
+5 -10
View File
@@ -630,11 +630,9 @@ fn deserialize_newtype_variant(
}) })
} }
}; };
// The outer braces are unnecessary but quasi used to have them. We can quote! {
// remove them separately from the syn conversion. Ok(#type_ident::#variant_ident(#visit)),
quote!({ }
Ok(#type_ident::#variant_ident(#visit))
})
} }
fn deserialize_field_visitor( fn deserialize_field_visitor(
@@ -865,14 +863,11 @@ fn deserialize_map(
Some(path) => { Some(path) => {
let (wrapper, wrapper_impl, wrapper_ty) = wrap_deserialize_with( let (wrapper, wrapper_impl, wrapper_ty) = wrap_deserialize_with(
type_ident, impl_generics, field.ty, path); type_ident, impl_generics, field.ty, path);
// The outer parentheses are redundant but quasi used to put quote!({
// them in. We can remove them separately from the syn
// conversion.
quote!(({
#wrapper #wrapper
#wrapper_impl #wrapper_impl
try!(visitor.visit_value::<#wrapper_ty>()).value try!(visitor.visit_value::<#wrapper_ty>()).value
})) })
} }
}; };
quote! { quote! {
+21 -33
View File
@@ -279,9 +279,7 @@ fn serialize_variant(
); );
quote! { quote! {
// The braces are unnecessary but quasi used to put them in. We #type_ident::#variant_ident(ref __simple_value) => #block,
// can remove them separately from the syn conversion.
#type_ident::#variant_ident(ref __simple_value) => { #block },
} }
}, },
Style::Tuple => { Style::Tuple => {
@@ -462,15 +460,11 @@ fn serialize_tuple_struct_visitor(
} }
let ser = quote! { let ser = quote! {
// This line should end in a semicolon but quasi used to behave try!(_serializer.#func(&mut __serde_state, #field_expr));
// differently between skipped and non-skipped so I have
// preserved that behavior. We can update it separately from the
// syn conversion.
try!(_serializer.#func(&mut __serde_state, #field_expr))
}; };
match skip { match skip {
None => quote!(#ser;), None => ser,
Some(skip) => quote!(if !#skip { #ser }), Some(skip) => quote!(if !#skip { #ser }),
} }
}) })
@@ -505,15 +499,11 @@ fn serialize_struct_visitor(
} }
let ser = quote! { let ser = quote! {
// This line should end in a semicolon but quasi used to behave try!(_serializer.#func(&mut __serde_state, #key_expr, #field_expr));
// differently between skipped and non-skipped so I have
// preserved that behavior. We can update it separately from the
// syn conversion.
try!(_serializer.#func(&mut __serde_state, #key_expr, #field_expr))
}; };
match skip { match skip {
None => quote!(#ser;), None => ser,
Some(skip) => quote!(if !#skip { #ser }), Some(skip) => quote!(if !#skip { #ser }),
} }
}) })
@@ -540,27 +530,25 @@ fn wrap_serialize_with(
.build() .build()
.build(); .build();
quote! { quote!({
{ struct __SerializeWith #wrapper_generics #where_clause {
struct __SerializeWith #wrapper_generics #where_clause { value: &'__a #field_ty,
value: &'__a #field_ty, phantom: ::std::marker::PhantomData<#item_ty>,
phantom: ::std::marker::PhantomData<#item_ty>, }
}
impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause { impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause {
fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error> fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error>
where __S: _serde::ser::Serializer where __S: _serde::ser::Serializer
{ {
#path(self.value, __s) #path(self.value, __s)
}
}
__SerializeWith {
value: #value,
phantom: ::std::marker::PhantomData::<#item_ty>,
} }
} }
}
__SerializeWith {
value: #value,
phantom: ::std::marker::PhantomData::<#item_ty>,
}
})
} }
// Serialization of an empty struct results in code like: // Serialization of an empty struct results in code like: