From bed692e50edc2b6620b20eb6272d33e9a65b45aa Mon Sep 17 00:00:00 2001 From: Bernardo Uriarte Date: Sun, 4 Sep 2022 19:08:10 +0200 Subject: [PATCH] simplify and avoid duplication --- .../salsa-2022-macros/src/salsa_struct.rs | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index 11913349..5e1c0019 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -319,34 +319,29 @@ impl SalsaStruct { let field_getter = field.get_name(); let field_ty = field.ty(); + let field_debug = quote_spanned! { field.field.span() => + debug_struct = debug_struct.field( + #field_name_string, + &::salsa::debug::helper::SalsaDebug::<#field_ty, #db_type>::salsa_debug( + #[allow(clippy::needless_borrow)] + &self.#field_getter(_db), + _db, + _include_all_fields + ) + ); + }; + if self.is_identity_field(field) { - parse_quote_spanned! {field.field.span() => - debug_struct = debug_struct.field( - #field_name_string, - &::salsa::debug::helper::SalsaDebug::<#field_ty, #db_type>::salsa_debug( - #[allow(clippy::needless_borrow)] - &self.#field_getter(_db), - _db, - _include_all_fields - ) - ); + quote_spanned! { field.field.span() => + #field_debug } } else { - parse_quote_spanned! {field.field.span() => + quote_spanned! { field.field.span() => if _include_all_fields { - debug_struct = debug_struct.field( - #field_name_string, - &::salsa::debug::helper::SalsaDebug::<#field_ty, #db_type>::salsa_debug( - #[allow(clippy::needless_borrow)] - &self.#field_getter(_db), - _db, - true - ) - ); + #field_debug } } } - }) .collect::();