Skip to content

Commit f68f32d

Browse files
authored
Merge pull request #564 from serde-rs/cleanup
Clean up syn workarounds
2 parents 49d24a1 + 6ccb6c9 commit f68f32d

File tree

2 files changed

+25
-42
lines changed

2 files changed

+25
-42
lines changed

serde_codegen/src/de.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,9 @@ fn deserialize_newtype_variant(
630630
})
631631
}
632632
};
633-
// The outer braces are unnecessary but quasi used to have them. We can
634-
// remove them separately from the syn conversion.
635-
quote!({
636-
Ok(#type_ident::#variant_ident(#visit))
637-
})
633+
quote! {
634+
Ok(#type_ident::#variant_ident(#visit)),
635+
}
638636
}
639637

640638
fn deserialize_field_visitor(
@@ -865,14 +863,11 @@ fn deserialize_map(
865863
Some(path) => {
866864
let (wrapper, wrapper_impl, wrapper_ty) = wrap_deserialize_with(
867865
type_ident, impl_generics, field.ty, path);
868-
// The outer parentheses are redundant but quasi used to put
869-
// them in. We can remove them separately from the syn
870-
// conversion.
871-
quote!(({
866+
quote!({
872867
#wrapper
873868
#wrapper_impl
874869
try!(visitor.visit_value::<#wrapper_ty>()).value
875-
}))
870+
})
876871
}
877872
};
878873
quote! {

serde_codegen/src/ser.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ fn serialize_variant(
279279
);
280280

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

464462
let ser = quote! {
465-
// This line should end in a semicolon but quasi used to behave
466-
// differently between skipped and non-skipped so I have
467-
// preserved that behavior. We can update it separately from the
468-
// syn conversion.
469-
try!(_serializer.#func(&mut __serde_state, #field_expr))
463+
try!(_serializer.#func(&mut __serde_state, #field_expr));
470464
};
471465

472466
match skip {
473-
None => quote!(#ser;),
467+
None => ser,
474468
Some(skip) => quote!(if !#skip { #ser }),
475469
}
476470
})
@@ -505,15 +499,11 @@ fn serialize_struct_visitor(
505499
}
506500

507501
let ser = quote! {
508-
// This line should end in a semicolon but quasi used to behave
509-
// differently between skipped and non-skipped so I have
510-
// preserved that behavior. We can update it separately from the
511-
// syn conversion.
512-
try!(_serializer.#func(&mut __serde_state, #key_expr, #field_expr))
502+
try!(_serializer.#func(&mut __serde_state, #key_expr, #field_expr));
513503
};
514504

515505
match skip {
516-
None => quote!(#ser;),
506+
None => ser,
517507
Some(skip) => quote!(if !#skip { #ser }),
518508
}
519509
})
@@ -540,27 +530,25 @@ fn wrap_serialize_with(
540530
.build()
541531
.build();
542532

543-
quote! {
544-
{
545-
struct __SerializeWith #wrapper_generics #where_clause {
546-
value: &'__a #field_ty,
547-
phantom: ::std::marker::PhantomData<#item_ty>,
548-
}
533+
quote!({
534+
struct __SerializeWith #wrapper_generics #where_clause {
535+
value: &'__a #field_ty,
536+
phantom: ::std::marker::PhantomData<#item_ty>,
537+
}
549538

550-
impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause {
551-
fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error>
552-
where __S: _serde::ser::Serializer
553-
{
554-
#path(self.value, __s)
555-
}
539+
impl #wrapper_generics _serde::ser::Serialize for #wrapper_ty #where_clause {
540+
fn serialize<__S>(&self, __s: &mut __S) -> ::std::result::Result<(), __S::Error>
541+
where __S: _serde::ser::Serializer
542+
{
543+
#path(self.value, __s)
556544
}
545+
}
557546

558-
__SerializeWith {
559-
value: #value,
560-
phantom: ::std::marker::PhantomData::<#item_ty>,
561-
}
547+
__SerializeWith {
548+
value: #value,
549+
phantom: ::std::marker::PhantomData::<#item_ty>,
562550
}
563-
}
551+
})
564552
}
565553

566554
// Serialization of an empty struct results in code like:

0 commit comments

Comments
 (0)