Allow `?Sized` bounds in some cases
authorMatt Corallo <git@bluematt.me>
Mon, 17 Jul 2023 02:14:12 +0000 (02:14 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Jul 2023 23:06:00 +0000 (23:06 +0000)
c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs

index a7f7a1e3896b16941064d3d273c0a54b2aa25540..28cce19e9715067a150a194f496b7e27eb03e640 100644 (file)
@@ -532,7 +532,12 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                                syn::TypeParamBound::Trait(tr) => {
                                                                        writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
                                                                        for bound in bounds_iter {
-                                                                               if let syn::TypeParamBound::Trait(_) = bound { panic!("11"); }
+                                                                               if let syn::TypeParamBound::Trait(t) = bound {
+                                                                                       // We only allow for `?Sized` here.
+                                                                                       if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
+                                                                                       assert_eq!(t.path.segments.len(), 1);
+                                                                                       assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
+                                                                               }
                                                                        }
                                                                        break;
                                                                },
index 608a34aa8834ecb47a8597891916f4358de08c4d..e45fdca095ddb5552cb72f95d81bc631af2b0ff1 100644 (file)
@@ -215,7 +215,7 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                        'bound_loop: for bound in type_param.bounds.iter() {
                                                if let syn::TypeParamBound::Trait(trait_bound) = bound {
                                                        if let Some(ident) = single_ident_generic_path_to_ident(&trait_bound.path) {
-                                                               match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, _ => {} }
+                                                               match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, "Sized" => continue, _ => {} }
                                                        }
                                                        if path_matches_nongeneric(&trait_bound.path, &["core", "clone", "Clone"]) { continue; }
 
@@ -352,7 +352,12 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                                        }
                                                                } else { unimplemented!(); }
                                                                for bound in bounds_iter {
-                                                                       if let syn::TypeParamBound::Trait(_) = bound { unimplemented!(); }
+                                                                       if let syn::TypeParamBound::Trait(t) = bound {
+                                                                               // We only allow for `?Sized` here.
+                                                                               if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
+                                                                               assert_eq!(t.path.segments.len(), 1);
+                                                                               assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
+                                                                       }
                                                                }
                                                                break;
                                                        },