From 4f282d4cdae9b2e79e4fd604b629517898f02262 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 17 Jul 2023 02:14:12 +0000 Subject: [PATCH] Allow `?Sized` bounds in some cases --- c-bindings-gen/src/main.rs | 7 ++++++- c-bindings-gen/src/types.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index a7f7a1e..28cce19 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -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; }, diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 608a34a..e45fdca 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -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; }, -- 2.30.2