Skip to content

Commit

Permalink
Merge pull request #2841 from dtolnay/serializewith
Browse files Browse the repository at this point in the history
Reduce scope of quote_spanned on SerializeWith wrapper
  • Loading branch information
dtolnay authored Oct 22, 2024
2 parents 00460b8 + ab4f3f3 commit 830309f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 1 addition & 6 deletions serde_derive/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand All @@ -1238,7 +1240,7 @@ fn wrap_serialize_with(
where
__S: _serde::Serializer,
{
#serialize_with(#(self.values.#field_access, )* __s)
#wrapper_serialize
}
}

Expand Down

0 comments on commit 830309f

Please sign in to comment.