Skip to content

Commit

Permalink
Get rid of #deserializer_var, use more straightforward approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Oct 25, 2024
1 parent fc5d8fe commit 8b68ced
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,25 +511,18 @@ fn deserialize_tuple(
TupleForm::Tuple if nfields == 1 => {
let field = &fields[0];
let field_ty = field.ty;
let deserializer_var = quote!(__e);

let value = match field.attrs.deserialize_with() {
let deserialize = match field.attrs.deserialize_with() {
None => {
let span = field.original.span();
let func =
quote_spanned!(span=> <#field_ty as _serde::Deserialize>::deserialize);
quote! {
#func(#deserializer_var)?
}
quote_spanned!(span=> <#field_ty as _serde::Deserialize>::deserialize)
}
Some(path) => {
// If #path returns wrong type, error will be reported here (^^^^^).
// We attach span of the path to the function so it will be reported
// on the #[serde(with = "...")]
// ^^^^^
quote_spanned! {path.span()=>
#path(#deserializer_var)?
}
quote_spanned!(path.span()=> #path)
}
};

Expand All @@ -544,11 +537,11 @@ fn deserialize_tuple(

Some(quote! {
#[inline]
fn visit_newtype_struct<__E>(self, #deserializer_var: __E) -> _serde::__private::Result<Self::Value, __E::Error>
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::__private::Result<Self::Value, __E::Error>
where
__E: _serde::Deserializer<#delife>,
{
let __field0: #field_ty = #value;
let __field0: #field_ty = #deserialize(__e)?;
_serde::__private::Ok(#result)
}
})
Expand Down

0 comments on commit 8b68ced

Please sign in to comment.