From 758b09018c411eaf99aa50c31aa553fd50fbc94f Mon Sep 17 00:00:00 2001 From: Sebastian Goll Date: Sat, 22 Feb 2025 12:47:44 +0100 Subject: [PATCH] Simplify formatting code, avoid trailing `,` after macro formatting --- diesel_cli/src/print_schema.rs | 23 ++++++++----------- .../postgres/expected.snap | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/diesel_cli/src/print_schema.rs b/diesel_cli/src/print_schema.rs index 4a79404a62e9..51e102918cf0 100644 --- a/diesel_cli/src/print_schema.rs +++ b/diesel_cli/src/print_schema.rs @@ -603,26 +603,23 @@ impl Display for TableDefinitions<'_> { vec![self.tables.iter().map(|table| &table.name).collect()] } }; - is_first = true; - for tables in table_groups { - if tables.len() < 2 { - continue; - } - - if is_first { + for (table_group_index, table_group) in table_groups + .into_iter() + .filter(|table_group| table_group.len() >= 2) + .enumerate() + { + if table_group_index == 0 { writeln!(f)?; - is_first = false; } write!(f, "diesel::allow_tables_to_appear_in_same_query!(")?; { let mut out = PadAdapter::new(f); writeln!(out)?; - for table in tables { - if table.rust_name == table.sql_name { - writeln!(out, "{},", table.sql_name)?; - } else { - writeln!(out, "{},", table.rust_name)?; + for (table_index, table) in table_group.into_iter().enumerate() { + if table_index != 0 { + write!(out, ", ")?; } + write!(out, "{}", table.rust_name)?; } } writeln!(f, ");")?; diff --git a/diesel_cli/tests/print_schema/print_schema_allow_tables_in_same_query/postgres/expected.snap b/diesel_cli/tests/print_schema/print_schema_allow_tables_in_same_query/postgres/expected.snap index 17eaf7a8cf4e..ae28fda95549 100644 --- a/diesel_cli/tests/print_schema/print_schema_allow_tables_in_same_query/postgres/expected.snap +++ b/diesel_cli/tests/print_schema/print_schema_allow_tables_in_same_query/postgres/expected.snap @@ -55,5 +55,5 @@ diesel::joinable!(comments -> posts (post_id)); diesel::joinable!(posts -> users (user_id)); diesel::joinable!(transactions -> sessions (session_id)); -diesel::allow_tables_to_appear_in_same_query!(comments, posts, users,); -diesel::allow_tables_to_appear_in_same_query!(sessions, transactions,); +diesel::allow_tables_to_appear_in_same_query!(comments, posts, users); +diesel::allow_tables_to_appear_in_same_query!(sessions, transactions);