Merge pull request #2841 from dtolnay/serializewith

Reduce scope of quote_spanned on SerializeWith wrapper
This commit is contained in:
David Tolnay 2024-10-21 21:56:51 -07:00 committed by GitHub
commit 830309fcb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View File

@ -14,12 +14,7 @@ pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> Token
quote! {
#[doc(hidden)]
#[allow(
clippy::needless_lifetimes,
non_upper_case_globals,
unused_attributes,
unused_qualifications,
)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#use_serde
#code

View File

@ -1224,11 +1224,13 @@ fn wrap_serialize_with(
// We attach span of the path to this piece so error will be reported
// on the #[serde(with = "...")]
// ^^^^^
quote_spanned!(serialize_with.span()=> {
let wrapper_serialize = quote_spanned! {serialize_with.span()=>
#serialize_with(#(self.values.#field_access, )* __s)
};
quote!({
#[doc(hidden)]
struct __SerializeWith #wrapper_impl_generics #where_clause {
// If #field_tys is empty, this field is unused
#[allow(dead_code)]
values: (#(&'__a #field_tys, )*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
}
@ -1238,7 +1240,7 @@ fn wrap_serialize_with(
where
__S: _serde::Serializer,
{
#serialize_with(#(self.values.#field_access, )* __s)
#wrapper_serialize
}
}