Skip to content

Commit

Permalink
Eliminate #[macro_use] from serde_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 26, 2023
1 parent dd99136 commit 0fb672a
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 20 deletions.
8 changes: 3 additions & 5 deletions precompiled/serde_derive/src/lib_from_source.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#[macro_use]
extern crate quote;
#[macro_use]
extern crate syn;
extern crate proc_macro;
extern crate proc_macro2;
extern crate quote;
extern crate syn;

#[macro_use]
mod bound;
Expand All @@ -19,7 +17,7 @@ mod this;
mod try;

use proc_macro::TokenStream;
use syn::DeriveInput;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
Expand Down
1 change: 1 addition & 0 deletions serde_derive/src/bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::internals::{attr, ungroup};
use proc_macro2::Span;
use std::collections::HashSet;
use syn::punctuated::{Pair, Punctuated};
use syn::Token;

// Remove the default from every type parameter because in the generated impls
// they look like associated types: "error: associated type bindings are not
Expand Down
4 changes: 2 additions & 2 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::{attr, replace_receiver, ungroup, Ctxt, Derive};
use crate::{bound, dummy, pretend, this};
use proc_macro2::{Literal, Span, TokenStream};
use quote::ToTokens;
use quote::{quote, quote_spanned, ToTokens};
use std::collections::BTreeSet;
use std::ptr;
#[cfg(precompiled)]
use std::sync::atomic::Ordering;
use syn::punctuated::Punctuated;
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> {
replace_receiver(input);
Expand Down
1 change: 1 addition & 0 deletions serde_derive/src/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::try;
use proc_macro2::TokenStream;
use quote::quote;

pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
let try_replacement = try::replacement();
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/fragment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::token;
use syn::{token, Token};

pub enum Fragment {
/// Tokens that can be used as an expression.
Expand Down
1 change: 1 addition & 0 deletions serde_derive/src/internals/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::internals::{attr, check, Ctxt, Derive};
use syn::punctuated::Punctuated;
use syn::Token;

/// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`,
/// parsed into an internal representation.
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::iter::FromIterator;
use syn::meta::ParseNestedMeta;
use syn::parse::ParseStream;
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
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/internals/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::mem;
use syn::punctuated::Punctuated;
use syn::{
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) {
Expand Down
7 changes: 2 additions & 5 deletions serde_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@
)]
#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]

#[macro_use]
extern crate proc_macro2;
extern crate quote;
#[macro_use]
extern crate syn;

#[cfg(not(precompiled))]
extern crate proc_macro;
extern crate proc_macro2;

#[cfg(precompiled)]
extern crate proc_macro2 as proc_macro;

Expand All @@ -80,7 +77,7 @@ mod internals;
use proc_macro::TokenStream;
#[cfg(precompiled)]
use std::sync::atomic::AtomicBool;
use syn::DeriveInput;
use syn::{parse_macro_input, DeriveInput};

#[macro_use]
mod bound;
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/pretend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::internals::ast::{Container, Data, Field, Style, Variant};
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
// derive. Other than this pretend code, a struct annotated with remote derive
Expand Down
3 changes: 2 additions & 1 deletion serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
use crate::{bound, dummy, pretend, this};
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_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> {
replace_receiver(input);
Expand Down
1 change: 1 addition & 0 deletions serde_derive/src/try.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use proc_macro2::{Punct, Spacing, TokenStream};
use quote::quote;

// None of our generated code requires the `From::from` error conversion
// performed by the standard library's `try!` macro. With this simplified macro
Expand Down
4 changes: 1 addition & 3 deletions serde_derive_internals/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
clippy::wildcard_imports
)]

#[macro_use]
extern crate syn;

extern crate proc_macro2;
extern crate quote;
extern crate syn;

#[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")]
#[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")]
Expand Down

0 comments on commit 0fb672a

Please sign in to comment.