From 6885ea073e5f950e62af4cb7102ae2b030501e48 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 29 May 2018 11:24:40 -0700 Subject: [PATCH] Only derive extra traits when the `extra-traits` feature is enabled --- crates/backend/Cargo.toml | 3 ++- crates/backend/src/ast.rs | 32 +++++++++++++++++--------------- crates/backend/src/lib.rs | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index 7b9f5efe3..0b92c93ff 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -12,10 +12,11 @@ Backend code generation of the wasm-bindgen tool [features] spans = ["proc-macro2/nightly"] +extra-traits = ["syn/extra-traits"] [dependencies] quote = '0.6' proc-macro2 = "0.4" wasm-bindgen-shared = { path = "../shared", version = "=0.2.11" } -syn = { version = '0.14', features = ['extra-traits', 'full', 'visit-mut'] } +syn = { version = '0.14', features = ['full', 'visit-mut'] } serde_json = "1.0" diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index b922bd3dc..ebb89ff4a 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -3,7 +3,8 @@ use quote::ToTokens; use shared; use syn; -#[derive(Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] +#[derive(Default)] pub struct Program { pub exports: Vec, pub imports: Vec, @@ -11,7 +12,7 @@ pub struct Program { pub structs: Vec, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Export { pub class: Option, pub method: bool, @@ -20,7 +21,7 @@ pub struct Export { pub function: Function, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Import { pub module: Option, pub version: Option, @@ -28,14 +29,14 @@ pub struct Import { pub kind: ImportKind, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub enum ImportKind { Function(ImportFunction), Static(ImportStatic), Type(ImportType), } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct ImportFunction { pub function: Function, pub rust_name: Ident, @@ -43,14 +44,14 @@ pub struct ImportFunction { pub shim: Ident, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub enum ImportFunctionKind { Method { class: String, ty: syn::Type }, JsConstructor { class: String, ty: syn::Type }, Normal, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct ImportStatic { pub vis: syn::Visibility, pub ty: syn::Type, @@ -59,13 +60,13 @@ pub struct ImportStatic { pub js_name: Ident, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct ImportType { pub vis: syn::Visibility, pub name: Ident, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Function { pub name: Ident, pub arguments: Vec, @@ -76,13 +77,13 @@ pub struct Function { pub rust_vis: syn::Visibility, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Struct { pub name: Ident, pub fields: Vec, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct StructField { pub opts: BindgenAttrs, pub name: Ident, @@ -92,13 +93,13 @@ pub struct StructField { pub setter: Ident, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Enum { pub name: Ident, pub variants: Vec, } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] pub struct Variant { pub name: Ident, pub value: u32, @@ -769,7 +770,8 @@ impl StructField { } } -#[derive(Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] +#[derive(Default)] pub struct BindgenAttrs { attrs: Vec, } @@ -930,7 +932,7 @@ impl syn::synom::Synom for BindgenAttrs { )); } -#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] enum BindgenAttr { Catch, Constructor, diff --git a/crates/backend/src/lib.rs b/crates/backend/src/lib.rs index f3f24428e..19ad1957c 100755 --- a/crates/backend/src/lib.rs +++ b/crates/backend/src/lib.rs @@ -1,5 +1,5 @@ #![recursion_limit = "256"] -#![deny(missing_debug_implementations)] +#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))] extern crate proc_macro2; #[macro_use]