Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions serde_codegen/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,9 @@ fn deserialize_newtype_variant(
})
}
};
// The outer braces are unnecessary but quasi used to have them. We can
// remove them separately from the syn conversion.
quote!({
Ok(#type_ident::#variant_ident(#visit))
})
quote! {
Ok(#type_ident::#variant_ident(#visit)),
}
}

fn deserialize_field_visitor(
Expand Down Expand Up @@ -865,14 +863,11 @@ fn deserialize_map(
Some(path) => {
let (wrapper, wrapper_impl, wrapper_ty) = wrap_deserialize_with(
type_ident, impl_generics, field.ty, path);
// The outer parentheses are redundant but quasi used to put
// them in. We can remove them separately from the syn
// conversion.
quote!(({
quote!({
#wrapper
#wrapper_impl
try!(visitor.visit_value::<#wrapper_ty>()).value
}))
})
}
};
quote! {
Expand Down
52 changes: 20 additions & 32 deletions serde_codegen/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ fn serialize_variant(
);

quote! {
// The braces are unnecessary but quasi used to put them in. We
// can remove them separately from the syn conversion.
#type_ident::#variant_ident(ref __simple_value) => { #block },
#type_ident::#variant_ident(ref __simple_value) => #block,
}
},
Style::Tuple => {
Expand Down Expand Up @@ -462,15 +460,11 @@ fn serialize_tuple_struct_visitor(
}

let ser = quote! {
// This line should end in a semicolon but quasi used to behave
// 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))
try!(_serializer.#func(&mut __serde_state, #field_expr));
};

match skip {
None => quote!(#ser;),
None => ser,
Some(skip) => quote!(if !#skip { #ser }),
}
})
Expand Down Expand Up @@ -505,15 +499,11 @@ fn serialize_struct_visitor(
}

let ser = quote! {
// This line should end in a semicolon but quasi used to behave
// 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))
try!(_serializer.#func(&mut __serde_state, #key_expr, #field_expr));
};

match skip {
None => quote!(#ser;),
None => ser,
Some(skip) => quote!(if !#skip { #ser }),
}
})
Expand All @@ -540,27 +530,25 @@ fn wrap_serialize_with(
.build()
.build();

quote! {
{
struct __SerializeWith #wrapper_generics #where_clause {
value: &'__a #field_ty,
phantom: ::std::marker::PhantomData<#item_ty>,
}
quote!({
struct __SerializeWith #wrapper_generics #where_clause {
value: &'__a #field_ty,
phantom: ::std::marker::PhantomData<#item_ty>,
}

impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause {
fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error>
where __S: _serde::ser::Serializer
{
#path(self.value, __s)
}
impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause {
fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error>
where __S: _serde::ser::Serializer
{
#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:
Expand Down