Skip to content

Commit

Permalink
Fix struct literal newline
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed May 17, 2024
1 parent f5ef1b8 commit cc3bb3f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/bindgen/language_backend/clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -942,6 +943,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
}
}
}
out.pop_tab();
write!(out, " }}");
}
}
Expand Down

0 comments on commit cc3bb3f

Please sign in to comment.