Format serde_derive generated where-clauses

This commit is contained in:
David Tolnay 2018-05-05 18:24:16 -07:00
parent 40479336c1
commit f263e3fcec
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 80 additions and 40 deletions

View File

@ -42,7 +42,8 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<Tokens, Str
quote! { quote! {
impl #de_impl_generics #ident #ty_generics #where_clause { 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 deserialize<__D>(__deserializer: __D) -> _serde::export::Result<#remote #ty_generics, __D::Error>
where __D: _serde::Deserializer<#delife> where
__D: _serde::Deserializer<#delife>,
{ {
#used #used
#body #body
@ -56,7 +57,8 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<Tokens, Str
#[automatically_derived] #[automatically_derived]
impl #de_impl_generics _serde::Deserialize<#delife> for #ident #ty_generics #where_clause { impl #de_impl_generics _serde::Deserialize<#delife> for #ident #ty_generics #where_clause {
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error> fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
where __D: _serde::Deserializer<#delife> where
__D: _serde::Deserializer<#delife>,
{ {
#body #body
} }
@ -296,7 +298,8 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
let fn_deserialize_in_place = quote_block! { let fn_deserialize_in_place = quote_block! {
fn deserialize_in_place<__D>(__deserializer: __D, __place: &mut Self) -> _serde::export::Result<(), __D::Error> fn deserialize_in_place<__D>(__deserializer: __D, __place: &mut Self) -> _serde::export::Result<(), __D::Error>
where __D: _serde::Deserializer<#delife> where
__D: _serde::Deserializer<#delife>,
{ {
#stmts #stmts
} }
@ -336,7 +339,8 @@ fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fra
#[inline] #[inline]
fn visit_unit<__E>(self) -> _serde::export::Result<Self::Value, __E> fn visit_unit<__E>(self) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(#this) _serde::export::Ok(#this)
} }
@ -432,7 +436,8 @@ fn deserialize_tuple(
#[inline] #[inline]
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<#delife> where
__A: _serde::de::SeqAccess<#delife>,
{ {
#visit_seq #visit_seq
} }
@ -520,7 +525,8 @@ fn deserialize_tuple_in_place(
#[inline] #[inline]
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<#delife> where
__A: _serde::de::SeqAccess<#delife>,
{ {
#visit_seq #visit_seq
} }
@ -745,7 +751,8 @@ fn deserialize_newtype_struct(type_path: &Tokens, params: &Parameters, field: &F
quote! { quote! {
#[inline] #[inline]
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error> fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error>
where __E: _serde::Deserializer<#delife> where
__E: _serde::Deserializer<#delife>,
{ {
let __field0: #field_ty = #value; let __field0: #field_ty = #value;
_serde::export::Ok(#result) _serde::export::Ok(#result)
@ -763,7 +770,8 @@ fn deserialize_newtype_struct_in_place(params: &Parameters, field: &Field) -> To
quote! { quote! {
#[inline] #[inline]
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error> fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error>
where __E: _serde::Deserializer<#delife> where
__E: _serde::Deserializer<#delife>,
{ {
_serde::Deserialize::deserialize_in_place(__e, &mut self.place.0) _serde::Deserialize::deserialize_in_place(__e, &mut self.place.0)
} }
@ -858,7 +866,8 @@ fn deserialize_struct(
Untagged::No if !cattrs.has_flatten() => Some(quote! { Untagged::No if !cattrs.has_flatten() => Some(quote! {
#[inline] #[inline]
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<#delife> where
__A: _serde::de::SeqAccess<#delife>,
{ {
#visit_seq #visit_seq
} }
@ -885,7 +894,8 @@ fn deserialize_struct(
#[inline] #[inline]
fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::MapAccess<#delife> where
__A: _serde::de::MapAccess<#delife>,
{ {
#visit_map #visit_map
} }
@ -963,7 +973,8 @@ fn deserialize_struct_in_place(
let visit_seq = quote! { let visit_seq = quote! {
#[inline] #[inline]
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<#delife> where
__A: _serde::de::SeqAccess<#delife>,
{ {
#visit_seq #visit_seq
} }
@ -992,7 +1003,8 @@ fn deserialize_struct_in_place(
#[inline] #[inline]
fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::MapAccess<#delife> where
__A: _serde::de::MapAccess<#delife>,
{ {
#visit_map #visit_map
} }
@ -1111,7 +1123,8 @@ fn deserialize_externally_tagged_enum(
} }
fn visit_enum<__A>(self, __data: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_enum<__A>(self, __data: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::EnumAccess<#delife> where
__A: _serde::de::EnumAccess<#delife>,
{ {
#match_variant #match_variant
} }
@ -1361,7 +1374,8 @@ fn deserialize_adjacently_tagged_enum(
type Value = #this #ty_generics; type Value = #this #ty_generics;
fn deserialize<__D>(self, __deserializer: __D) -> _serde::export::Result<Self::Value, __D::Error> fn deserialize<__D>(self, __deserializer: __D) -> _serde::export::Result<Self::Value, __D::Error>
where __D: _serde::Deserializer<#delife> where
__D: _serde::Deserializer<#delife>,
{ {
match self.field { match self.field {
#(#variant_arms)* #(#variant_arms)*
@ -1382,7 +1396,8 @@ fn deserialize_adjacently_tagged_enum(
} }
fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::MapAccess<#delife> where
__A: _serde::de::MapAccess<#delife>,
{ {
// Visit the first relevant key. // Visit the first relevant key.
match #next_relevant_key { match #next_relevant_key {
@ -1446,7 +1461,8 @@ fn deserialize_adjacently_tagged_enum(
} }
fn visit_seq<__A>(self, mut __seq: __A) -> _serde::export::Result<Self::Value, __A::Error> fn visit_seq<__A>(self, mut __seq: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<#delife> where
__A: _serde::de::SeqAccess<#delife>,
{ {
// Visit the first element - the tag. // Visit the first element - the tag.
match try!(_serde::de::SeqAccess::next_element(&mut __seq)) { match try!(_serde::de::SeqAccess::next_element(&mut __seq)) {
@ -1766,7 +1782,8 @@ fn deserialize_generated_identifier(
impl<'de> _serde::Deserialize<'de> for __Field #lifetime { impl<'de> _serde::Deserialize<'de> for __Field #lifetime {
#[inline] #[inline]
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error> fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
where __D: _serde::Deserializer<'de> where
__D: _serde::Deserializer<'de>,
{ {
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) _serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
} }
@ -1942,85 +1959,99 @@ fn deserialize_identifier(
let visit_other = if collect_other_fields { let visit_other = if collect_other_fields {
quote! { quote! {
fn visit_bool<__E>(self, __value: bool) -> _serde::export::Result<Self::Value, __E> fn visit_bool<__E>(self, __value: bool) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::Bool(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::Bool(__value)))
} }
fn visit_i8<__E>(self, __value: i8) -> _serde::export::Result<Self::Value, __E> fn visit_i8<__E>(self, __value: i8) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::I8(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::I8(__value)))
} }
fn visit_i16<__E>(self, __value: i16) -> _serde::export::Result<Self::Value, __E> fn visit_i16<__E>(self, __value: i16) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::I16(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::I16(__value)))
} }
fn visit_i32<__E>(self, __value: i32) -> _serde::export::Result<Self::Value, __E> fn visit_i32<__E>(self, __value: i32) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::I32(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::I32(__value)))
} }
fn visit_i64<__E>(self, __value: i64) -> _serde::export::Result<Self::Value, __E> fn visit_i64<__E>(self, __value: i64) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::I64(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::I64(__value)))
} }
fn visit_u8<__E>(self, __value: u8) -> _serde::export::Result<Self::Value, __E> fn visit_u8<__E>(self, __value: u8) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::U8(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::U8(__value)))
} }
fn visit_u16<__E>(self, __value: u16) -> _serde::export::Result<Self::Value, __E> fn visit_u16<__E>(self, __value: u16) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::U16(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::U16(__value)))
} }
fn visit_u32<__E>(self, __value: u32) -> _serde::export::Result<Self::Value, __E> fn visit_u32<__E>(self, __value: u32) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::U32(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::U32(__value)))
} }
fn visit_u64<__E>(self, __value: u64) -> _serde::export::Result<Self::Value, __E> fn visit_u64<__E>(self, __value: u64) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::U64(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::U64(__value)))
} }
fn visit_f32<__E>(self, __value: f32) -> _serde::export::Result<Self::Value, __E> fn visit_f32<__E>(self, __value: f32) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::F32(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::F32(__value)))
} }
fn visit_f64<__E>(self, __value: f64) -> _serde::export::Result<Self::Value, __E> fn visit_f64<__E>(self, __value: f64) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::F64(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::F64(__value)))
} }
fn visit_char<__E>(self, __value: char) -> _serde::export::Result<Self::Value, __E> fn visit_char<__E>(self, __value: char) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::Char(__value))) _serde::export::Ok(__Field::__other(_serde::private::de::Content::Char(__value)))
} }
fn visit_unit<__E>(self) -> _serde::export::Result<Self::Value, __E> fn visit_unit<__E>(self) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
_serde::export::Ok(__Field::__other(_serde::private::de::Content::Unit)) _serde::export::Ok(__Field::__other(_serde::private::de::Content::Unit))
} }
fn visit_borrowed_str<__E>(self, __value: &'de str) -> _serde::export::Result<Self::Value, __E> fn visit_borrowed_str<__E>(self, __value: &'de str) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
match __value { match __value {
#( #(
@ -2034,7 +2065,8 @@ fn deserialize_identifier(
} }
fn visit_borrowed_bytes<__E>(self, __value: &'de [u8]) -> _serde::export::Result<Self::Value, __E> fn visit_borrowed_bytes<__E>(self, __value: &'de [u8]) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
match __value { match __value {
#( #(
@ -2051,7 +2083,8 @@ fn deserialize_identifier(
} else { } else {
quote! { quote! {
fn visit_u64<__E>(self, __value: u64) -> _serde::export::Result<Self::Value, __E> fn visit_u64<__E>(self, __value: u64) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
match __value { match __value {
#( #(
@ -2073,7 +2106,8 @@ fn deserialize_identifier(
#visit_other #visit_other
fn visit_str<__E>(self, __value: &str) -> _serde::export::Result<Self::Value, __E> fn visit_str<__E>(self, __value: &str) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
match __value { match __value {
#( #(
@ -2087,7 +2121,8 @@ fn deserialize_identifier(
} }
fn visit_bytes<__E>(self, __value: &[u8]) -> _serde::export::Result<Self::Value, __E> fn visit_bytes<__E>(self, __value: &[u8]) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error where
__E: _serde::de::Error,
{ {
match __value { match __value {
#( #(
@ -2561,7 +2596,8 @@ fn wrap_deserialize_with(
impl #de_impl_generics _serde::Deserialize<#delife> for __DeserializeWith #de_ty_generics #where_clause { impl #de_impl_generics _serde::Deserialize<#delife> for __DeserializeWith #de_ty_generics #where_clause {
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error> fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
where __D: _serde::Deserializer<#delife> where
__D: _serde::Deserializer<#delife>,
{ {
_serde::export::Ok(__DeserializeWith { _serde::export::Ok(__DeserializeWith {
value: try!(#deserialize_with(__deserializer)), value: try!(#deserialize_with(__deserializer)),

View File

@ -38,7 +38,8 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, Strin
quote! { quote! {
impl #impl_generics #ident #ty_generics #where_clause { 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 serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
where __S: _serde::Serializer where
__S: _serde::Serializer,
{ {
#used #used
#body #body
@ -50,7 +51,8 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, Strin
#[automatically_derived] #[automatically_derived]
impl #impl_generics _serde::Serialize for #ident #ty_generics #where_clause { impl #impl_generics _serde::Serialize for #ident #ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error> fn serialize<__S>(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
where __S: _serde::Serializer where
__S: _serde::Serializer,
{ {
#body #body
} }
@ -658,7 +660,8 @@ fn serialize_adjacently_tagged_variant(
impl #wrapper_impl_generics _serde::Serialize for __AdjacentlyTagged #wrapper_ty_generics #where_clause { impl #wrapper_impl_generics _serde::Serialize for __AdjacentlyTagged #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error> fn serialize<__S>(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
where __S: _serde::Serializer where
__S: _serde::Serializer,
{ {
let (#(#fields_ident,)*) = self.data; let (#(#fields_ident,)*) = self.data;
#inner #inner
@ -1037,7 +1040,8 @@ fn wrap_serialize_with(
impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause { impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __s: __S) -> _serde::export::Result<__S::Ok, __S::Error> fn serialize<__S>(&self, __s: __S) -> _serde::export::Result<__S::Ok, __S::Error>
where __S: _serde::Serializer where
__S: _serde::Serializer,
{ {
#serialize_with(#(self.values.#field_access, )* __s) #serialize_with(#(self.values.#field_access, )* __s)
} }