From 8369e376b05af6a2db07032ba579cd292109de83 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 28 May 2022 19:23:40 -0400 Subject: [PATCH] Don't wrap 1-tuples in parens --- bindgen/src/bindgen_rs.rs | 64 ++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/bindgen/src/bindgen_rs.rs b/bindgen/src/bindgen_rs.rs index 6f4931c868..4322cd5432 100644 --- a/bindgen/src/bindgen_rs.rs +++ b/bindgen/src/bindgen_rs.rs @@ -1570,33 +1570,47 @@ fn tag_union_struct_help<'a, I: Iterator, L: Display + P .collect::>() .join("\n") ); - let owned_ret = { - let lines = ret_values - .iter() - .map(|line| format!("\n{INDENT}{INDENT}{INDENT}{line}")) - .collect::>() - .join(", "); + let owned_ret; + let borrowed_ret; + let owned_ret_type; + let borrowed_ret_type; - format!("({lines}\n{INDENT}{INDENT})") - }; - let borrowed_ret = { - let lines = ret_values - .iter() - .map(|line| format!("\n{INDENT}{INDENT}{INDENT}&{line}")) - .collect::>() - .join(", "); + if ret_types.len() == 1 { + owned_ret_type = ret_types.join(""); + borrowed_ret_type = owned_ret_type.clone(); - format!("({lines}\n{INDENT}{INDENT})") - }; - let owned_ret_type = format!("({})", ret_types.join(", ")); - let borrowed_ret_type = format!( - "({})", - ret_types - .iter() - .map(|ret_type| { format!("&{ret_type}") }) - .collect::>() - .join(", ") - ); + let ret_val = ret_values.first().unwrap(); + owned_ret = format!("\n{INDENT}{INDENT}{ret_val}"); + borrowed_ret = format!("\n{INDENT}{INDENT}&{ret_val}"); + } else { + owned_ret_type = format!("({})", ret_types.join(", ")); + borrowed_ret_type = format!( + "({})", + ret_types + .iter() + .map(|ret_type| { format!("&{ret_type}") }) + .collect::>() + .join(", ") + ); + owned_ret = { + let lines = ret_values + .iter() + .map(|line| format!("\n{INDENT}{INDENT}{INDENT}{line}")) + .collect::>() + .join(", "); + + format!("({lines}\n{INDENT}{INDENT})") + }; + borrowed_ret = { + let lines = ret_values + .iter() + .map(|line| format!("\n{INDENT}{INDENT}{INDENT}&{line}")) + .collect::>() + .join(", "); + + format!("({lines}\n{INDENT}{INDENT})") + }; + } StructIngredients { payload_args,