mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-24 06:27:59 +00:00
add #[allow(deprecated)] to derive implementations
Allow deprecated in the `Serialize`/`Deserialize` derive implementations. This allows you to deprecate structs, enums, struct fields, or enum variants and not get compiler warnings/errors about use of deprecated thing. We only do this if `#[deprecated]` or `#[allow(deprecated)]` exist on the root object or the variants of the root object (if it is an enum). Resolves #2195
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::fragment::{Fragment, Match, Stmts};
|
||||
use crate::internals::ast::{Container, Data, Field, Style, Variant};
|
||||
use crate::internals::deprecated::allow_deprecated;
|
||||
use crate::internals::name::Name;
|
||||
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
|
||||
use crate::{bound, dummy, pretend, this};
|
||||
@@ -18,6 +19,7 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
|
||||
};
|
||||
precondition(&ctxt, &cont);
|
||||
ctxt.check()?;
|
||||
let allow_deprecated = allow_deprecated(input)?;
|
||||
|
||||
let ident = &cont.ident;
|
||||
let params = Parameters::new(&cont);
|
||||
@@ -30,6 +32,7 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
|
||||
let used = pretend::pretend_used(&cont, params.is_packed);
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
#allow_deprecated
|
||||
impl #impl_generics #ident #ty_generics #where_clause {
|
||||
#vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> #serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
@@ -43,6 +46,7 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
|
||||
} else {
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
#allow_deprecated
|
||||
impl #impl_generics #serde::Serialize for #ident #ty_generics #where_clause {
|
||||
fn serialize<__S>(&self, __serializer: __S) -> #serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user