From 3859f58d9b2624f7f0ca32e3b4a6557fea94bdee Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 5 May 2018 23:06:16 -0700 Subject: [PATCH] Move derive internals into serde_derive crate We can continue to publish serde_derive_internals independently but serde_derive no longer has a dependency on it. This improves compile time of serde_derive by 7%. --- serde_derive/Cargo.toml | 1 - .../src => serde_derive/src/internals}/ast.rs | 6 +++--- .../src => serde_derive/src/internals}/attr.rs | 5 +++-- .../src => serde_derive/src/internals}/case.rs | 0 .../src => serde_derive/src/internals}/check.rs | 6 +++--- .../src => serde_derive/src/internals}/ctxt.rs | 0 serde_derive/src/internals/mod.rs | 16 ++++++++++++++++ serde_derive/src/lib.rs | 4 ++-- serde_derive_internals/Cargo.toml | 5 ++++- serde_derive_internals/{src => }/lib.rs | 10 +++------- serde_derive_internals/src | 1 + 11 files changed, 35 insertions(+), 19 deletions(-) rename {serde_derive_internals/src => serde_derive/src/internals}/ast.rs (98%) rename {serde_derive_internals/src => serde_derive/src/internals}/attr.rs (99%) rename {serde_derive_internals/src => serde_derive/src/internals}/case.rs (100%) rename {serde_derive_internals/src => serde_derive/src/internals}/check.rs (98%) rename {serde_derive_internals/src => serde_derive/src/internals}/ctxt.rs (100%) create mode 100644 serde_derive/src/internals/mod.rs rename serde_derive_internals/{src => }/lib.rs (88%) create mode 120000 serde_derive_internals/src diff --git a/serde_derive/Cargo.toml b/serde_derive/Cargo.toml index c308bf75..6966637d 100644 --- a/serde_derive/Cargo.toml +++ b/serde_derive/Cargo.toml @@ -25,7 +25,6 @@ proc-macro = true [dependencies] proc-macro2 = "0.3" quote = "0.5.2" -serde_derive_internals = { version = "=0.23.1", default-features = false, path = "../serde_derive_internals" } syn = { version = "0.13", features = ["visit"] } [dev-dependencies] diff --git a/serde_derive_internals/src/ast.rs b/serde_derive/src/internals/ast.rs similarity index 98% rename from serde_derive_internals/src/ast.rs rename to serde_derive/src/internals/ast.rs index 89fac302..9ccb62f5 100644 --- a/serde_derive_internals/src/ast.rs +++ b/serde_derive/src/internals/ast.rs @@ -6,11 +6,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use attr; -use check; +use internals::attr; +use internals::check; +use internals::Ctxt; use syn; use syn::punctuated::Punctuated; -use Ctxt; pub struct Container<'a> { pub ident: syn::Ident, diff --git a/serde_derive_internals/src/attr.rs b/serde_derive/src/internals/attr.rs similarity index 99% rename from serde_derive_internals/src/attr.rs rename to serde_derive/src/internals/attr.rs index 06271a7f..bc60a6e3 100644 --- a/serde_derive_internals/src/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -6,6 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use internals::Ctxt; use proc_macro2::{Group, Span, TokenStream, TokenTree}; use std::collections::BTreeSet; use std::str::FromStr; @@ -15,7 +16,6 @@ use syn::synom::{ParseError, Synom}; use syn::Ident; use syn::Meta::{List, NameValue, Word}; use syn::NestedMeta::{Literal, Meta}; -use Ctxt; // This module handles parsing of `#[serde(...)]` attributes. The entrypoints // are `attr::Container::from_ast`, `attr::Variant::from_ast`, and @@ -25,7 +25,7 @@ use Ctxt; // user will see errors simultaneously for all bad attributes in the crate // rather than just the first. -pub use case::RenameRule; +pub use internals::case::RenameRule; #[derive(Copy, Clone)] struct Attr<'c, T> { @@ -167,6 +167,7 @@ pub enum Identifier { } impl Identifier { + #[cfg(feature = "deserialize_in_place")] pub fn is_some(self) -> bool { match self { Identifier::No => false, diff --git a/serde_derive_internals/src/case.rs b/serde_derive/src/internals/case.rs similarity index 100% rename from serde_derive_internals/src/case.rs rename to serde_derive/src/internals/case.rs diff --git a/serde_derive_internals/src/check.rs b/serde_derive/src/internals/check.rs similarity index 98% rename from serde_derive_internals/src/check.rs rename to serde_derive/src/internals/check.rs index 6ca8275b..639f95e9 100644 --- a/serde_derive_internals/src/check.rs +++ b/serde_derive/src/internals/check.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{Container, Data, Style}; -use attr::{EnumTag, Identifier}; -use Ctxt; +use internals::ast::{Container, Data, Style}; +use internals::attr::{EnumTag, Identifier}; +use internals::Ctxt; /// Cross-cutting checks that require looking at more than a single attrs /// object. Simpler checks should happen when parsing and building the attrs. diff --git a/serde_derive_internals/src/ctxt.rs b/serde_derive/src/internals/ctxt.rs similarity index 100% rename from serde_derive_internals/src/ctxt.rs rename to serde_derive/src/internals/ctxt.rs diff --git a/serde_derive/src/internals/mod.rs b/serde_derive/src/internals/mod.rs new file mode 100644 index 00000000..f68462c9 --- /dev/null +++ b/serde_derive/src/internals/mod.rs @@ -0,0 +1,16 @@ +// Copyright 2017 Serde Developers +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub mod ast; +pub mod attr; + +mod ctxt; +pub use self::ctxt::Ctxt; + +mod case; +mod check; diff --git a/serde_derive/src/lib.rs b/serde_derive/src/lib.rs index d20ef78d..cd6304ec 100644 --- a/serde_derive/src/lib.rs +++ b/serde_derive/src/lib.rs @@ -35,11 +35,11 @@ extern crate quote; #[macro_use] extern crate syn; -extern crate serde_derive_internals as internals; - extern crate proc_macro; extern crate proc_macro2; +mod internals; + use proc_macro::TokenStream; use syn::DeriveInput; diff --git a/serde_derive_internals/Cargo.toml b/serde_derive_internals/Cargo.toml index 45d11906..a782149a 100644 --- a/serde_derive_internals/Cargo.toml +++ b/serde_derive_internals/Cargo.toml @@ -9,7 +9,10 @@ repository = "https://github.com/serde-rs/serde" documentation = "https://docs.serde.rs/serde_derive_internals/" keywords = ["serde", "serialization"] readme = "README.md" -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +include = ["Cargo.toml", "lib.rs", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] + +[lib] +path = "lib.rs" [dependencies] proc-macro2 = "0.3" diff --git a/serde_derive_internals/src/lib.rs b/serde_derive_internals/lib.rs similarity index 88% rename from serde_derive_internals/src/lib.rs rename to serde_derive_internals/lib.rs index 03a48102..cbd307b9 100644 --- a/serde_derive_internals/src/lib.rs +++ b/serde_derive_internals/lib.rs @@ -17,11 +17,7 @@ extern crate syn; extern crate proc_macro2; -pub mod ast; -pub mod attr; +#[path = "src/mod.rs"] +mod internals; -mod ctxt; -pub use ctxt::Ctxt; - -mod case; -mod check; +pub use internals::*; diff --git a/serde_derive_internals/src b/serde_derive_internals/src new file mode 120000 index 00000000..f1a565f2 --- /dev/null +++ b/serde_derive_internals/src @@ -0,0 +1 @@ +../serde_derive/src/internals/ \ No newline at end of file