mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 19:31:02 +00:00
Work around deprecation of str::trim_left_matches
This commit is contained in:
+2
-19
@@ -5,11 +5,11 @@ use syn::spanned::Spanned;
|
|||||||
use syn::{self, Ident, Index, Member};
|
use syn::{self, Ident, Index, Member};
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
|
use dummy;
|
||||||
use fragment::{Expr, Fragment, Match, Stmts};
|
use fragment::{Expr, Fragment, Match, Stmts};
|
||||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use internals::{attr, Ctxt, Derive};
|
use internals::{attr, Ctxt, Derive};
|
||||||
use pretend;
|
use pretend;
|
||||||
use try;
|
|
||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
@@ -25,11 +25,6 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(¶ms);
|
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(¶ms);
|
||||||
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
|
|
||||||
let dummy_const = Ident::new(
|
|
||||||
&format!("_IMPL_DESERIALIZE_FOR_{}", suffix),
|
|
||||||
Span::call_site(),
|
|
||||||
);
|
|
||||||
let body = Stmts(deserialize_body(&cont, ¶ms));
|
let body = Stmts(deserialize_body(&cont, ¶ms));
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
@@ -65,19 +60,7 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let try_replacement = try::replacement();
|
Ok(dummy::wrap_in_const("DESERIALIZE", ident, impl_block))
|
||||||
let generated = quote! {
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const #dummy_const: () = {
|
|
||||||
#[allow(unknown_lints)]
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
|
||||||
#[allow(rust_2018_idioms)]
|
|
||||||
extern crate serde as _serde;
|
|
||||||
#try_replacement
|
|
||||||
#impl_block
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Ok(generated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn precondition(cx: &Ctxt, cont: &Container) {
|
fn precondition(cx: &Ctxt, cont: &Container) {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
use proc_macro2::{Ident, Span, TokenStream};
|
||||||
|
|
||||||
|
use try;
|
||||||
|
|
||||||
|
pub fn wrap_in_const(trait_: &str, ty: &Ident, code: TokenStream) -> TokenStream {
|
||||||
|
let try_replacement = try::replacement();
|
||||||
|
|
||||||
|
let dummy_const = Ident::new(
|
||||||
|
&format!("_IMPL_{}_FOR_{}", trait_, unraw(ty)),
|
||||||
|
Span::call_site(),
|
||||||
|
);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
|
const #dummy_const: () = {
|
||||||
|
#[allow(unknown_lints)]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
||||||
|
#[allow(rust_2018_idioms)]
|
||||||
|
extern crate serde as _serde;
|
||||||
|
#try_replacement
|
||||||
|
#code
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
|
fn unraw(ident: &Ident) -> String {
|
||||||
|
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
|
||||||
|
// in 1.33. We currently support rustc back to 1.15 so we need to continue
|
||||||
|
// to use the deprecated one.
|
||||||
|
ident.to_string().trim_left_matches("r#").to_owned()
|
||||||
|
}
|
||||||
@@ -95,7 +95,11 @@ pub struct Name {
|
|||||||
deserialize: String,
|
deserialize: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
fn unraw(ident: &Ident) -> String {
|
fn unraw(ident: &Ident) -> String {
|
||||||
|
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
|
||||||
|
// in 1.33. We currently support rustc back to 1.15 so we need to continue
|
||||||
|
// to use the deprecated one.
|
||||||
ident.to_string().trim_left_matches("r#").to_owned()
|
ident.to_string().trim_left_matches("r#").to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ mod bound;
|
|||||||
mod fragment;
|
mod fragment;
|
||||||
|
|
||||||
mod de;
|
mod de;
|
||||||
|
mod dummy;
|
||||||
mod pretend;
|
mod pretend;
|
||||||
mod ser;
|
mod ser;
|
||||||
mod try;
|
mod try;
|
||||||
|
|||||||
+2
-19
@@ -3,11 +3,11 @@ use syn::spanned::Spanned;
|
|||||||
use syn::{self, Ident, Index, Member};
|
use syn::{self, Ident, Index, Member};
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
|
use dummy;
|
||||||
use fragment::{Fragment, Match, Stmts};
|
use fragment::{Fragment, Match, Stmts};
|
||||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use internals::{attr, Ctxt, Derive};
|
use internals::{attr, Ctxt, Derive};
|
||||||
use pretend;
|
use pretend;
|
||||||
use try;
|
|
||||||
|
|
||||||
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
@@ -21,11 +21,6 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
|
||||||
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
|
|
||||||
let dummy_const = Ident::new(
|
|
||||||
&format!("_IMPL_SERIALIZE_FOR_{}", suffix),
|
|
||||||
Span::call_site(),
|
|
||||||
);
|
|
||||||
let body = Stmts(serialize_body(&cont, ¶ms));
|
let body = Stmts(serialize_body(&cont, ¶ms));
|
||||||
|
|
||||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||||
@@ -56,19 +51,7 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let try_replacement = try::replacement();
|
Ok(dummy::wrap_in_const("SERIALIZE", ident, impl_block))
|
||||||
let generated = quote! {
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const #dummy_const: () = {
|
|
||||||
#[allow(unknown_lints)]
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
|
||||||
#[allow(rust_2018_idioms)]
|
|
||||||
extern crate serde as _serde;
|
|
||||||
#try_replacement
|
|
||||||
#impl_block
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Ok(generated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn precondition(cx: &Ctxt, cont: &Container) {
|
fn precondition(cx: &Ctxt, cont: &Container) {
|
||||||
|
|||||||
Reference in New Issue
Block a user