Correctly set the `c_ty` arg on `write_c_type` calls for generic params
authorMatt Corallo <git@bluematt.me>
Fri, 24 Jun 2022 01:16:46 +0000 (01:16 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Jun 2022 21:27:19 +0000 (21:27 +0000)
This corrects some cases where we have to print generic types that
themselves have generic parameters.

c-bindings-gen/src/main.rs

index 266bf5877508ec24133c5c009244a3162b1facf2..88258632d81694a9c59be831125c9d60d98c9d24 100644 (file)
@@ -1610,15 +1610,15 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
                                writeln_field_docs(w, &field.attrs, "\t\t", types, Some(&gen_types), &field.ty);
                                write!(w, "\t\t{}: ", field.ident.as_ref().unwrap()).unwrap();
                                write!(&mut constr, "{}{}: ", if idx != 0 { ", " } else { "" }, field.ident.as_ref().unwrap()).unwrap();
-                               types.write_c_type(w, &field.ty, Some(&gen_types), false);
-                               types.write_c_type(&mut constr, &field.ty, Some(&gen_types), false);
+                               types.write_c_type(w, &field.ty, Some(&gen_types), true);
+                               types.write_c_type(&mut constr, &field.ty, Some(&gen_types), true);
                                writeln!(w, ",").unwrap();
                        }
                        write!(w, "\t}}").unwrap();
                } else if let syn::Fields::Unnamed(fields) = &var.fields {
                        if fields.unnamed.len() == 1 {
                                let mut empty_check = Vec::new();
-                               types.write_c_type(&mut empty_check, &fields.unnamed[0].ty, Some(&gen_types), false);
+                               types.write_c_type(&mut empty_check, &fields.unnamed[0].ty, Some(&gen_types), true);
                                if empty_check.is_empty() {
                                        empty_tuple_variant = true;
                                }
@@ -1629,8 +1629,8 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
                                for (idx, field) in fields.unnamed.iter().enumerate() {
                                        if export_status(&field.attrs) == ExportStatus::TestOnly { continue; }
                                        write!(&mut constr, "{}: ", ('a' as u8 + idx as u8) as char).unwrap();
-                                       types.write_c_type(w, &field.ty, Some(&gen_types), false);
-                                       types.write_c_type(&mut constr, &field.ty, Some(&gen_types), false);
+                                       types.write_c_type(w, &field.ty, Some(&gen_types), true);
+                                       types.write_c_type(&mut constr, &field.ty, Some(&gen_types), true);
                                        if idx != fields.unnamed.len() - 1 {
                                                write!(w, ",").unwrap();
                                                write!(&mut constr, ",").unwrap();
@@ -1679,7 +1679,7 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
                                } else if let syn::Fields::Unnamed(fields) = &var.fields {
                                        if fields.unnamed.len() == 1 {
                                                let mut empty_check = Vec::new();
-                                               types.write_c_type(&mut empty_check, &fields.unnamed[0].ty, Some(&gen_types), false);
+                                               types.write_c_type(&mut empty_check, &fields.unnamed[0].ty, Some(&gen_types), true);
                                                if empty_check.is_empty() {
                                                        empty_tuple_variant = true;
                                                }