Skip to content

Commit 4f282d4

Browse files
committed
Allow ?Sized bounds in some cases
1 parent 05cfd2e commit 4f282d4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

c-bindings-gen/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,12 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
532532
syn::TypeParamBound::Trait(tr) => {
533533
writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
534534
for bound in bounds_iter {
535-
if let syn::TypeParamBound::Trait(_) = bound { panic!("11"); }
535+
if let syn::TypeParamBound::Trait(t) = bound {
536+
// We only allow for `?Sized` here.
537+
if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
538+
assert_eq!(t.path.segments.len(), 1);
539+
assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
540+
}
536541
}
537542
break;
538543
},

c-bindings-gen/src/types.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
215215
'bound_loop: for bound in type_param.bounds.iter() {
216216
if let syn::TypeParamBound::Trait(trait_bound) = bound {
217217
if let Some(ident) = single_ident_generic_path_to_ident(&trait_bound.path) {
218-
match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, _ => {} }
218+
match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, "Sized" => continue, _ => {} }
219219
}
220220
if path_matches_nongeneric(&trait_bound.path, &["core", "clone", "Clone"]) { continue; }
221221

@@ -352,7 +352,12 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
352352
}
353353
} else { unimplemented!(); }
354354
for bound in bounds_iter {
355-
if let syn::TypeParamBound::Trait(_) = bound { unimplemented!(); }
355+
if let syn::TypeParamBound::Trait(t) = bound {
356+
// We only allow for `?Sized` here.
357+
if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
358+
assert_eq!(t.path.segments.len(), 1);
359+
assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
360+
}
356361
}
357362
break;
358363
},

0 commit comments

Comments
 (0)