From cc3bb3ff5df3e15374e4fb8f68017eb23dc64a1e Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 17 May 2024 18:09:35 +0900 Subject: [PATCH] Fix struct literal newline --- src/bindgen/language_backend/clike.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bindgen/language_backend/clike.rs b/src/bindgen/language_backend/clike.rs index af1bead9..0e011436 100644 --- a/src/bindgen/language_backend/clike.rs +++ b/src/bindgen/language_backend/clike.rs @@ -913,20 +913,21 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { } write!(out, "{{ "); + out.push_tab(); + let mut is_first_field = true; // In C++, same order as defined is required. let ordered_fields = out.bindings().struct_field_names(path); for ordered_key in ordered_fields.iter() { if let Some(lit) = fields.get(ordered_key) { if !is_first_field { - write!(out, ", "); + out.write(", "); } is_first_field = false; + out.new_line(); + let condition = lit.cfg.to_condition(self.config); - if condition.is_some() { - out.new_line(); - } condition.write_before(self.config, out); if self.config.language == Language::Cxx { // TODO: Some C++ versions (c++20?) now support designated @@ -942,6 +943,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { } } } + out.pop_tab(); write!(out, " }}"); } }