Skip to content

Commit

Permalink
Merge pull request #2426 from compiler-errors/dont-doc-private
Browse files Browse the repository at this point in the history
Make derived serializer/deserializer internals `doc(hidden)`
  • Loading branch information
dtolnay committed Apr 11, 2023
2 parents d6de911 + 5f3fd99 commit a80d830
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions serde_derive/src/de.rs
Expand Up @@ -419,6 +419,7 @@ fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fra
let expecting = cattrs.expecting().unwrap_or(&expecting);

quote_block! {
#[doc(hidden)]
struct __Visitor;

impl<'de> _serde::de::Visitor<'de> for __Visitor {
Expand Down Expand Up @@ -515,6 +516,7 @@ fn deserialize_tuple(
};

quote_block! {
#[doc(hidden)]
struct __Visitor #de_impl_generics #where_clause {
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -605,6 +607,7 @@ fn deserialize_tuple_in_place(
let place_life = place_lifetime();

quote_block! {
#[doc(hidden)]
struct __Visitor #in_place_impl_generics #where_clause {
place: &#place_life mut #this_type #ty_generics,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -1020,6 +1023,7 @@ fn deserialize_struct(
quote_block! {
#field_visitor

#[doc(hidden)]
struct __Visitor #de_impl_generics #where_clause {
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -1132,6 +1136,7 @@ fn deserialize_struct_in_place(
Some(quote_block! {
#field_visitor

#[doc(hidden)]
struct __Visitor #in_place_impl_generics #where_clause {
place: &#place_life mut #this_type #ty_generics,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -1203,6 +1208,7 @@ fn prepare_enum_variant_enum(
let variants_stmt = {
let variant_names = variant_names_idents.iter().map(|(name, _, _)| name);
quote! {
#[doc(hidden)]
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
}
};
Expand Down Expand Up @@ -1275,6 +1281,7 @@ fn deserialize_externally_tagged_enum(
quote_block! {
#variant_visitor

#[doc(hidden)]
struct __Visitor #de_impl_generics #where_clause {
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -1522,6 +1529,7 @@ fn deserialize_adjacently_tagged_enum(

#variants_stmt

#[doc(hidden)]
struct __Seed #de_impl_generics #where_clause {
field: __Field,
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
Expand All @@ -1541,6 +1549,7 @@ fn deserialize_adjacently_tagged_enum(
}
}

#[doc(hidden)]
struct __Visitor #de_impl_generics #where_clause {
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -1643,6 +1652,7 @@ fn deserialize_adjacently_tagged_enum(
}
}

#[doc(hidden)]
const FIELDS: &'static [&'static str] = &[#tag, #content];
_serde::Deserializer::deserialize_struct(
__deserializer,
Expand Down Expand Up @@ -1954,11 +1964,13 @@ fn deserialize_generated_identifier(

quote_block! {
#[allow(non_camel_case_types)]
#[doc(hidden)]
enum __Field #lifetime {
#(#field_idents,)*
#ignore_variant
}

#[doc(hidden)]
struct __FieldVisitor;

impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
Expand Down Expand Up @@ -2046,11 +2058,13 @@ fn deserialize_custom_identifier(
None
} else if is_variant {
let variants = quote! {
#[doc(hidden)]
const VARIANTS: &'static [&'static str] = &[ #(#names),* ];
};
Some(variants)
} else {
let fields = quote! {
#[doc(hidden)]
const FIELDS: &'static [&'static str] = &[ #(#names),* ];
};
Some(fields)
Expand All @@ -2072,6 +2086,7 @@ fn deserialize_custom_identifier(
quote_block! {
#names_const

#[doc(hidden)]
struct __FieldVisitor #de_impl_generics #where_clause {
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
lifetime: _serde::__private::PhantomData<&#delife ()>,
Expand Down Expand Up @@ -2406,6 +2421,7 @@ fn deserialize_struct_as_struct_visitor(
.flat_map(|(_, _, aliases)| aliases);

quote_block! {
#[doc(hidden)]
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
}
};
Expand Down Expand Up @@ -2684,6 +2700,7 @@ fn deserialize_struct_as_struct_in_place_visitor(
let fields_stmt = {
let field_names = field_names_idents.iter().map(|(name, _, _)| name);
quote_block! {
#[doc(hidden)]
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
}
};
Expand Down Expand Up @@ -2864,6 +2881,7 @@ fn wrap_deserialize_with(
let delife = params.borrowed.de_lifetime();

let wrapper = quote! {
#[doc(hidden)]
struct __DeserializeWith #de_impl_generics #where_clause {
value: #value_ty,
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
Expand Down
3 changes: 3 additions & 0 deletions serde_derive/src/ser.rs
Expand Up @@ -719,6 +719,7 @@ fn serialize_adjacently_tagged_variant(
let (wrapper_impl_generics, wrapper_ty_generics, _) = wrapper_generics.split_for_impl();

quote_block! {
#[doc(hidden)]
struct __AdjacentlyTagged #wrapper_generics #where_clause {
data: (#(&'__a #fields_ty,)*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
Expand Down Expand Up @@ -982,6 +983,7 @@ fn serialize_struct_variant_with_flatten(
let (wrapper_impl_generics, wrapper_ty_generics, _) = wrapper_generics.split_for_impl();

quote_block! {
#[doc(hidden)]
struct __EnumFlatten #wrapper_generics #where_clause {
data: (#(&'__a #fields_ty,)*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
Expand Down Expand Up @@ -1212,6 +1214,7 @@ fn wrap_serialize_with(
});

quote!({
#[doc(hidden)]
struct __SerializeWith #wrapper_impl_generics #where_clause {
values: (#(&'__a #field_tys, )*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
Expand Down

0 comments on commit a80d830

Please sign in to comment.