diff options
author | David Tolnay <dtolnay@gmail.com> | 2018-08-31 09:51:12 -0700 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2018-08-31 09:51:12 -0700 |
commit | 640239157f282aba0bd1105d4c3e19d4da41c107 (patch) | |
tree | ce34374c16d18600eb5e1703b59111c99a67187e /src | |
parent | 346c35eee294f5198e0158f9c92676206ac5fb81 (diff) | |
download | syn-640239157f282aba0bd1105d4c3e19d4da41c107.tar.gz |
Move TokensOrDefault out of root
Diffstat (limited to 'src')
-rw-r--r-- | src/data.rs | 3 | ||||
-rw-r--r-- | src/derive.rs | 5 | ||||
-rw-r--r-- | src/expr.rs | 8 | ||||
-rw-r--r-- | src/generics.rs | 5 | ||||
-rw-r--r-- | src/item.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 28 | ||||
-rw-r--r-- | src/path.rs | 3 | ||||
-rw-r--r-- | src/print.rs | 16 | ||||
-rw-r--r-- | src/ty.rs | 3 |
9 files changed, 49 insertions, 27 deletions
diff --git a/src/data.rs b/src/data.rs index fff1c847..fe20fe2e 100644 --- a/src/data.rs +++ b/src/data.rs @@ -318,9 +318,12 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; + use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; + use print::TokensOrDefault; + impl ToTokens for Variant { fn to_tokens(&self, tokens: &mut TokenStream) { tokens.append_all(&self.attrs); diff --git a/src/derive.rs b/src/derive.rs index a346950a..5c1bb17c 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -211,10 +211,13 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; - use attr::FilterAttrs; + use proc_macro2::TokenStream; use quote::ToTokens; + use attr::FilterAttrs; + use print::TokensOrDefault; + impl ToTokens for DeriveInput { fn to_tokens(&self, tokens: &mut TokenStream) { for attr in self.attrs.outer() { diff --git a/src/expr.rs b/src/expr.rs index 27b9eb50..ab3ba9ab 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2997,11 +2997,15 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; - #[cfg(feature = "full")] - use attr::FilterAttrs; + use proc_macro2::{Literal, TokenStream}; use quote::{ToTokens, TokenStreamExt}; + #[cfg(feature = "full")] + use attr::FilterAttrs; + #[cfg(feature = "full")] + use print::TokensOrDefault; + // If the given expression is a bare `ExprStruct`, wraps it in parenthesis // before appending it to `TokenStream`. #[cfg(feature = "full")] diff --git a/src/generics.rs b/src/generics.rs index 89034088..af233017 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -863,10 +863,13 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; - use attr::FilterAttrs; + use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; + use attr::FilterAttrs; + use print::TokensOrDefault; + impl ToTokens for Generics { fn to_tokens(&self, tokens: &mut TokenStream) { if self.params.is_empty() { diff --git a/src/item.rs b/src/item.rs index d95019d2..849594ed 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1977,10 +1977,13 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; - use attr::FilterAttrs; + use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; + use attr::FilterAttrs; + use print::TokensOrDefault; + impl ToTokens for ItemExternCrate { fn to_tokens(&self, tokens: &mut TokenStream) { tokens.append_all(self.attrs.outer()); @@ -582,6 +582,12 @@ pub mod parse; mod span; +#[cfg(all( + any(feature = "full", feature = "derive"), + feature = "printing" +))] +mod print; + //////////////////////////////////////////////////////////////////////////////// #[cfg(feature = "parsing")] @@ -807,25 +813,3 @@ macro_rules! parse_macro_input { }; }; } - -#[cfg(all( - any(feature = "full", feature = "derive"), - feature = "printing" -))] -struct TokensOrDefault<'a, T: 'a>(&'a Option<T>); - -#[cfg(all( - any(feature = "full", feature = "derive"), - feature = "printing" -))] -impl<'a, T> quote::ToTokens for TokensOrDefault<'a, T> -where - T: quote::ToTokens + Default, -{ - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - match *self.0 { - Some(ref t) => t.to_tokens(tokens), - None => T::default().to_tokens(tokens), - } - } -} diff --git a/src/path.rs b/src/path.rs index 2dafac84..e3ae9a7a 100644 --- a/src/path.rs +++ b/src/path.rs @@ -458,9 +458,12 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; + use proc_macro2::TokenStream; use quote::ToTokens; + use print::TokensOrDefault; + impl ToTokens for Path { fn to_tokens(&self, tokens: &mut TokenStream) { self.leading_colon.to_tokens(tokens); diff --git a/src/print.rs b/src/print.rs new file mode 100644 index 00000000..90570a04 --- /dev/null +++ b/src/print.rs @@ -0,0 +1,16 @@ +use proc_macro2::TokenStream; +use quote::ToTokens; + +pub struct TokensOrDefault<'a, T: 'a>(pub &'a Option<T>); + +impl<'a, T> ToTokens for TokensOrDefault<'a, T> +where + T: ToTokens + Default, +{ + fn to_tokens(&self, tokens: &mut TokenStream) { + match *self.0 { + Some(ref t) => t.to_tokens(tokens), + None => T::default().to_tokens(tokens), + } + } +} @@ -757,9 +757,12 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; + use proc_macro2::TokenStream; use quote::ToTokens; + use print::TokensOrDefault; + impl ToTokens for TypeSlice { fn to_tokens(&self, tokens: &mut TokenStream) { self.bracket_token.surround(tokens, |tokens| { |