Skip to content

Commit

Permalink
Hygiene for macro-generated newtype struct deserialization with 'with…
Browse files Browse the repository at this point in the history
…' attr
  • Loading branch information
dtolnay committed Oct 22, 2024
1 parent fdc36e5 commit b60e409
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,14 @@ fn deserialize_newtype_struct(
) -> TokenStream {
let delife = params.borrowed.de_lifetime();
let field_ty = field.ty;
let deserializer_var = quote!(__e);

let value = match field.attrs.deserialize_with() {
None => {
let span = field.original.span();
let func = quote_spanned!(span=> <#field_ty as _serde::Deserialize>::deserialize);
quote! {
#func(__e)?
#func(#deserializer_var)?
}
}
Some(path) => {
Expand All @@ -890,7 +891,7 @@ fn deserialize_newtype_struct(
// on the #[serde(with = "...")]
// ^^^^^
quote_spanned! {path.span()=>
#path(__e)?
#path(#deserializer_var)?
}
}
};
Expand All @@ -906,7 +907,7 @@ fn deserialize_newtype_struct(

quote! {
#[inline]
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::__private::Result<Self::Value, __E::Error>
fn visit_newtype_struct<__E>(self, #deserializer_var: __E) -> _serde::__private::Result<Self::Value, __E::Error>
where
__E: _serde::Deserializer<#delife>,
{
Expand Down

0 comments on commit b60e409

Please sign in to comment.