Hygiene fixes
This commit is contained in:
parent
ddc4b50d4d
commit
63623eb3b3
@ -32,9 +32,10 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<Tokens, Str
|
||||
|
||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||
let vis = &input.vis;
|
||||
let fun = quote_spanned!(Span::call_site()=> deserialize);
|
||||
quote! {
|
||||
impl #de_impl_generics #ident #ty_generics #where_clause {
|
||||
#vis fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<#remote #ty_generics, __D::Error>
|
||||
#vis fn #fun<__D>(__deserializer: __D) -> _serde::export::Result<#remote #ty_generics, __D::Error>
|
||||
where __D: _serde::Deserializer<#delife>
|
||||
{
|
||||
#body
|
||||
@ -562,14 +563,16 @@ fn deserialize_seq(
|
||||
}
|
||||
});
|
||||
|
||||
// FIXME: parentheses around field values are because of
|
||||
// https://github.com/rust-lang/rust/issues/47311
|
||||
let mut result = if is_struct {
|
||||
let names = fields.iter().map(|f| &f.ident);
|
||||
quote! {
|
||||
#type_path { #( #names: #vars ),* }
|
||||
quote_spanned! {Span::call_site()=>
|
||||
#type_path { #( #names: (#vars) ),* }
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#type_path ( #(#vars),* )
|
||||
quote_spanned! {Span::call_site()=>
|
||||
#type_path ( #((#vars)),* )
|
||||
}
|
||||
};
|
||||
|
||||
@ -629,10 +632,11 @@ fn deserialize_seq_in_place(
|
||||
span: Span::call_site(),
|
||||
}));
|
||||
|
||||
let dot = quote_spanned!(Span::call_site()=> .);
|
||||
if field.attrs.skip_deserializing() {
|
||||
let default = Expr(expr_is_missing(field, cattrs));
|
||||
quote! {
|
||||
self.place.#field_name = #default;
|
||||
self.place #dot #field_name = #default;
|
||||
}
|
||||
} else {
|
||||
let return_invalid_length = quote! {
|
||||
@ -642,7 +646,7 @@ fn deserialize_seq_in_place(
|
||||
None => {
|
||||
quote! {
|
||||
if let _serde::export::None = try!(_serde::de::SeqAccess::next_element_seed(&mut __seq,
|
||||
_serde::private::de::InPlaceSeed(&mut self.place.#field_name)))
|
||||
_serde::private::de::InPlaceSeed(&mut self.place #dot #field_name)))
|
||||
{
|
||||
#return_invalid_length
|
||||
}
|
||||
@ -655,7 +659,7 @@ fn deserialize_seq_in_place(
|
||||
#wrapper
|
||||
match try!(_serde::de::SeqAccess::next_element::<#wrapper_ty>(&mut __seq)) {
|
||||
_serde::export::Some(__wrap) => {
|
||||
self.place.#field_name = __wrap.value;
|
||||
self.place #dot #field_name = __wrap.value;
|
||||
}
|
||||
_serde::export::None => {
|
||||
#return_invalid_length
|
||||
@ -711,7 +715,9 @@ fn deserialize_newtype_struct(type_path: &Tokens, params: &Parameters, field: &F
|
||||
}
|
||||
};
|
||||
|
||||
let mut result = quote!(#type_path(#value));
|
||||
// FIXME: parentheses around field values are because of
|
||||
// https://github.com/rust-lang/rust/issues/47311
|
||||
let mut result = quote_spanned!(Span::call_site()=> #type_path((#value)));
|
||||
if params.has_getter {
|
||||
let this = ¶ms.this;
|
||||
result = quote! {
|
||||
@ -736,12 +742,13 @@ fn deserialize_newtype_struct_in_place(params: &Parameters, field: &Field) -> To
|
||||
|
||||
let delife = params.borrowed.de_lifetime();
|
||||
|
||||
let elem = quote_spanned!(Span::call_site()=> .0);
|
||||
quote! {
|
||||
#[inline]
|
||||
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error>
|
||||
where __E: _serde::Deserializer<#delife>
|
||||
{
|
||||
_serde::Deserialize::deserialize_in_place(__e, &mut self.place.0)
|
||||
_serde::Deserialize::deserialize_in_place(__e, &mut self.place #elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2042,13 +2049,15 @@ fn deserialize_map(
|
||||
}
|
||||
});
|
||||
|
||||
// FIXME: parentheses around field values are because of
|
||||
// https://github.com/rust-lang/rust/issues/47311
|
||||
let result = fields_names.iter().map(|&(field, ref name)| {
|
||||
let ident = field.ident.expect("struct contains unnamed fields");
|
||||
if field.attrs.skip_deserializing() {
|
||||
let value = Expr(expr_is_missing(field, cattrs));
|
||||
quote!(#ident: #value)
|
||||
quote_spanned!(Span::call_site()=> #ident: (#value))
|
||||
} else {
|
||||
quote!(#ident: #name)
|
||||
quote_spanned!(Span::call_site()=> #ident: (#name))
|
||||
}
|
||||
});
|
||||
|
||||
@ -2066,7 +2075,7 @@ fn deserialize_map(
|
||||
}
|
||||
};
|
||||
|
||||
let mut result = quote!(#struct_path { #(#result),* });
|
||||
let mut result = quote_spanned!(Span::call_site()=> #struct_path { #(#result),* });
|
||||
if params.has_getter {
|
||||
let this = ¶ms.this;
|
||||
result = quote! {
|
||||
|
@ -31,9 +31,10 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, Strin
|
||||
|
||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||
let vis = &input.vis;
|
||||
let fun = quote_spanned!(Span::call_site()=> serialize);
|
||||
quote! {
|
||||
impl #impl_generics #ident #ty_generics #where_clause {
|
||||
#vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
|
||||
#vis fn #fun<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
|
||||
where __S: _serde::Serializer
|
||||
{
|
||||
#body
|
||||
@ -990,11 +991,12 @@ fn get_member(params: &Parameters, field: &Field, member: &Member) -> Tokens {
|
||||
let self_var = ¶ms.self_var;
|
||||
match (params.is_remote, field.attrs.getter()) {
|
||||
(false, None) => {
|
||||
quote!(&#self_var.#member)
|
||||
quote_spanned!(Span::call_site()=> &#self_var.#member)
|
||||
}
|
||||
(true, None) => {
|
||||
let inner = quote_spanned!(Span::call_site()=> &#self_var.#member);
|
||||
let ty = field.ty;
|
||||
quote!(_serde::private::ser::constrain::<#ty>(&#self_var.#member))
|
||||
quote!(_serde::private::ser::constrain::<#ty>(#inner))
|
||||
}
|
||||
(true, Some(getter)) => {
|
||||
let ty = field.ty;
|
||||
|
@ -913,10 +913,24 @@ impl Field {
|
||||
// impl<'de: 'a, 'a> Deserialize<'de> for Cow<'a, str>
|
||||
// impl<'de: 'a, 'a> Deserialize<'de> for Cow<'a, [u8]>
|
||||
if is_cow(&field.ty, is_str) {
|
||||
let path = syn::parse_str("_serde::private::de::borrow_cow_str").unwrap();
|
||||
let mut path = syn::Path {
|
||||
leading_colon: None,
|
||||
segments: Punctuated::new(),
|
||||
};
|
||||
path.segments.push(Ident::new("_serde", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("private", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("de", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("borrow_cow_str", Span::def_site()).into());
|
||||
deserialize_with.set_if_none(path);
|
||||
} else if is_cow(&field.ty, is_slice_u8) {
|
||||
let path = syn::parse_str("_serde::private::de::borrow_cow_bytes").unwrap();
|
||||
let mut path = syn::Path {
|
||||
leading_colon: None,
|
||||
segments: Punctuated::new(),
|
||||
};
|
||||
path.segments.push(Ident::new("_serde", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("private", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("de", Span::def_site()).into());
|
||||
path.segments.push(Ident::new("borrow_cow_bytes", Span::def_site()).into());
|
||||
deserialize_with.set_if_none(path);
|
||||
}
|
||||
} else if is_rptr(&field.ty, is_str) || is_rptr(&field.ty, is_slice_u8) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user