Skip to content

Commit

Permalink
Strip uneeded default features from syn when compiling actual code
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Jul 23, 2020
1 parent 93cfaac commit f6cc161
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ quote = "1.0"
proc-macro2 = "1.0"
[dependencies.syn]
version = "1.0"
default-features = false
features = ["full"]

[dev-dependencies]
trybuild = "1.0"
impls = "1.0"
static_assertions = "1.1"
[dev-dependencies.syn]
version = "1.0"
default-features = false
features = ["full", "extra-traits"]

[features]
default = []
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extern crate quote;
use std::collections::HashSet;

use quote::quote;
use quote::ToTokens;
use syn::parse_macro_input;
use syn::parse_quote;
use syn::spanned::Spanned;

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -39,8 +39,10 @@ impl Args {
.collect::<syn::Result<Vec<&syn::Meta>>>()?;

for arg in meta {
// argument paths are compared against their token stream serialization
// to avoid to compile `syn` with the `extra-traits` feature
match arg {
syn::Meta::List(ref l) if l.path == parse_quote!(derive) => {
syn::Meta::List(ref l) if l.path.to_token_stream().to_string() == "derive" => {
for elem in l.nested.iter() {
if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = elem {
if let Some(d) = derive::Derive::from_path(&path) {
Expand All @@ -56,7 +58,9 @@ impl Args {
}
}
}
syn::Meta::NameValue(ref n) if n.path == parse_quote!(default) => {
syn::Meta::NameValue(ref n)
if n.path.to_token_stream().to_string() == "default" =>
{
if let syn::Lit::Str(ref s) = n.lit {
match syn::parse_str(&s.value()) {
Ok(path) if default.is_none() => {
Expand Down

0 comments on commit f6cc161

Please sign in to comment.