mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-09 20:11:01 +00:00
Eliminate #[macro_use] from serde_derive
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate quote;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate syn;
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
|
extern crate quote;
|
||||||
|
extern crate syn;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod bound;
|
mod bound;
|
||||||
@@ -19,7 +17,7 @@ mod this;
|
|||||||
mod try;
|
mod try;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use syn::DeriveInput;
|
use syn::{parse_macro_input, DeriveInput};
|
||||||
|
|
||||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::internals::{attr, ungroup};
|
|||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use syn::punctuated::{Pair, Punctuated};
|
use syn::punctuated::{Pair, Punctuated};
|
||||||
|
use syn::Token;
|
||||||
|
|
||||||
// Remove the default from every type parameter because in the generated impls
|
// Remove the default from every type parameter because in the generated impls
|
||||||
// they look like associated types: "error: associated type bindings are not
|
// they look like associated types: "error: associated type bindings are not
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ use crate::internals::ast::{Container, Data, Field, Style, Variant};
|
|||||||
use crate::internals::{attr, replace_receiver, ungroup, Ctxt, Derive};
|
use crate::internals::{attr, replace_receiver, ungroup, Ctxt, Derive};
|
||||||
use crate::{bound, dummy, pretend, this};
|
use crate::{bound, dummy, pretend, this};
|
||||||
use proc_macro2::{Literal, Span, TokenStream};
|
use proc_macro2::{Literal, Span, TokenStream};
|
||||||
use quote::ToTokens;
|
use quote::{quote, quote_spanned, ToTokens};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
#[cfg(precompiled)]
|
#[cfg(precompiled)]
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
use syn::{self, Ident, Index, Member};
|
use syn::{parse_quote, Ident, Index, Member};
|
||||||
|
|
||||||
pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
||||||
replace_receiver(input);
|
replace_receiver(input);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::try;
|
use crate::try;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
|
pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
|
||||||
let try_replacement = try::replacement();
|
let try_replacement = try::replacement();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::token;
|
use syn::{token, Token};
|
||||||
|
|
||||||
pub enum Fragment {
|
pub enum Fragment {
|
||||||
/// Tokens that can be used as an expression.
|
/// Tokens that can be used as an expression.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::internals::{attr, check, Ctxt, Derive};
|
use crate::internals::{attr, check, Ctxt, Derive};
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::Token;
|
||||||
|
|
||||||
/// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`,
|
/// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`,
|
||||||
/// parsed into an internal representation.
|
/// parsed into an internal representation.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::iter::FromIterator;
|
|||||||
use syn::meta::ParseNestedMeta;
|
use syn::meta::ParseNestedMeta;
|
||||||
use syn::parse::ParseStream;
|
use syn::parse::ParseStream;
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
use syn::{token, Ident, Lifetime};
|
use syn::{parse_quote, token, Ident, Lifetime, Token};
|
||||||
|
|
||||||
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
|
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
|
||||||
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
|
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::mem;
|
|||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
use syn::{
|
use syn::{
|
||||||
parse_quote, Data, DeriveInput, Expr, ExprPath, GenericArgument, GenericParam, Generics, Macro,
|
parse_quote, Data, DeriveInput, Expr, ExprPath, GenericArgument, GenericParam, Generics, Macro,
|
||||||
Path, PathArguments, QSelf, ReturnType, Type, TypeParamBound, TypePath, WherePredicate,
|
Path, PathArguments, QSelf, ReturnType, Token, Type, TypeParamBound, TypePath, WherePredicate,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn replace_receiver(input: &mut DeriveInput) {
|
pub fn replace_receiver(input: &mut DeriveInput) {
|
||||||
|
|||||||
@@ -63,15 +63,12 @@
|
|||||||
)]
|
)]
|
||||||
#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
|
#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
|
||||||
|
|
||||||
#[macro_use]
|
extern crate proc_macro2;
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
#[macro_use]
|
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
#[cfg(not(precompiled))]
|
#[cfg(not(precompiled))]
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
extern crate proc_macro2;
|
|
||||||
|
|
||||||
#[cfg(precompiled)]
|
#[cfg(precompiled)]
|
||||||
extern crate proc_macro2 as proc_macro;
|
extern crate proc_macro2 as proc_macro;
|
||||||
|
|
||||||
@@ -80,7 +77,7 @@ mod internals;
|
|||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
#[cfg(precompiled)]
|
#[cfg(precompiled)]
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use syn::DeriveInput;
|
use syn::{parse_macro_input, DeriveInput};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod bound;
|
mod bound;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::internals::ast::{Container, Data, Field, Style, Variant};
|
use crate::internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::format_ident;
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
// Suppress dead_code warnings that would otherwise appear when using a remote
|
// Suppress dead_code warnings that would otherwise appear when using a remote
|
||||||
// derive. Other than this pretend code, a struct annotated with remote derive
|
// derive. Other than this pretend code, a struct annotated with remote derive
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ use crate::internals::ast::{Container, Data, Field, Style, Variant};
|
|||||||
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
|
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
|
||||||
use crate::{bound, dummy, pretend, this};
|
use crate::{bound, dummy, pretend, this};
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
|
use quote::{quote, quote_spanned};
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
use syn::{self, Ident, Index, Member};
|
use syn::{parse_quote, Ident, Index, Member};
|
||||||
|
|
||||||
pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
||||||
replace_receiver(input);
|
replace_receiver(input);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use proc_macro2::{Punct, Spacing, TokenStream};
|
use proc_macro2::{Punct, Spacing, TokenStream};
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
// None of our generated code requires the `From::from` error conversion
|
// None of our generated code requires the `From::from` error conversion
|
||||||
// performed by the standard library's `try!` macro. With this simplified macro
|
// performed by the standard library's `try!` macro. With this simplified macro
|
||||||
|
|||||||
@@ -38,11 +38,9 @@
|
|||||||
clippy::wildcard_imports
|
clippy::wildcard_imports
|
||||||
)]
|
)]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate syn;
|
|
||||||
|
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
|
extern crate syn;
|
||||||
|
|
||||||
#[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")]
|
#[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")]
|
||||||
#[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")]
|
#[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")]
|
||||||
|
|||||||
Reference in New Issue
Block a user