Allow generation of manual types in reference options
authorMatt Corallo <git@bluematt.me>
Sat, 22 Jul 2023 20:03:11 +0000 (20:03 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Jul 2023 23:06:00 +0000 (23:06 +0000)
The limiting of supported types in `write_template_generics` isn't
super useful as its only called once per type - later uses of the
same type with the reference flag set or wiped doesn't change
anything. Still, it is relied on somewhat, so we can't drop it
entirely.

Now that we've moved more of the `[u8; 32]` newtypes to option
wrappers, failing for non-primitive references spuriously breaks.
Instead, we just allow it for manually-mapped types and let the
compiler complain if we do something invalid.

c-bindings-gen/src/types.rs

index e18c46518e03137a6de2c22936e32804a0cf703d..dc8c3b939d3e3c2bf737c60b451ca55c9fedf3cb 100644 (file)
@@ -2681,17 +2681,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                } else { unimplemented!(); }
                        } else if let syn::Type::Path(p_arg) = t {
                                if let Some(resolved) = self.maybe_resolve_path(&p_arg.path, generics) {
-                                       if !self.is_primitive(&resolved) {
+                                       if !self.is_primitive(&resolved) && self.c_type_from_path(&resolved, false, false).is_none() {
                                                if is_ref {
                                                        // We don't currently support outer reference types for non-primitive inners
                                                        return false;
                                                }
                                        }
                                } else {
-                                       if is_ref {
-                                               // We don't currently support outer reference types for non-primitive inners
-                                               return false;
-                                       }
+                                       return false;
                                }
                                if !self.write_c_type_intern(w, t, generics, false, false, false, true, true) { return false; }
                        } else {