From f0cbc97dc7ba74d8263cd7eff807c906f09cc56a Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Wed, 6 Jun 2018 18:40:45 -0700 Subject: [PATCH] Do not assign `field` to itself if no description specified when deriving input object (#187) If a field has a description, we properly generate a meta field definition like: ```rust { let field = registry.field::("id", &()); let field = field.description("Whatever"); field } ``` If a field does not have a description, we were generating something like: ```rust { let field = registry.field::("id", &()); let field = field; // <--- Note not needed field } ``` This of course works (and was likely optimized out by the compiler), but bloats generated code for no benefit. This change merely makes the second case generate: ```rust { let field = registry.field::("id", &()); field } ``` Fixes https://github.com/graphql-rust/juniper/issues/185. --- juniper_codegen/src/derive_input_object.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/juniper_codegen/src/derive_input_object.rs b/juniper_codegen/src/derive_input_object.rs index c0f30eed..653a5651 100644 --- a/juniper_codegen/src/derive_input_object.rs +++ b/juniper_codegen/src/derive_input_object.rs @@ -158,7 +158,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens { }; let field_description = match field_attrs.description { Some(s) => quote!{ let field = field.description(#s); }, - None => quote!{ let field = field; }, + None => quote!{}, }; let default = { @@ -207,7 +207,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens { }; meta_fields.push(meta_field); - // Buil from_input clause. + // Build from_input clause. let from_input_default = match default { Some(ref def) => {