Fix hygiene of macro-generated local variable accesses in serde(with) wrappers

This commit is contained in:
David Tolnay
2024-10-22 09:35:52 -07:00
parent 0058c7226e
commit 1e36ef551d
3 changed files with 14 additions and 6 deletions
+5 -2
View File
@@ -1220,12 +1220,15 @@ fn wrap_serialize_with(
})
});
let self_var = quote!(self);
let serializer_var = quote!(__s);
// If #serialize_with returns wrong type, error will be reported on here.
// We attach span of the path to this piece so error will be reported
// on the #[serde(with = "...")]
// ^^^^^
let wrapper_serialize = quote_spanned! {serialize_with.span()=>
#serialize_with(#(self.values.#field_access, )* __s)
#serialize_with(#(#self_var.values.#field_access, )* #serializer_var)
};
quote!({
@@ -1236,7 +1239,7 @@ fn wrap_serialize_with(
}
impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __s: __S) -> _serde::__private::Result<__S::Ok, __S::Error>
fn serialize<__S>(&#self_var, #serializer_var: __S) -> _serde::__private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{