@@ -73,7 +73,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
73
73
let mut for_obj_vec = Vec :: new ( ) ;
74
74
types. write_c_type ( & mut for_obj_vec, for_ty, Some ( generics) , false ) ;
75
75
full_obj_path = String :: from_utf8 ( for_obj_vec) . unwrap ( ) ;
76
- assert ! ( full_obj_path. starts_with( TypeResolver :: generated_container_path( ) ) ) ;
76
+ if ! full_obj_path. starts_with ( TypeResolver :: generated_container_path ( ) ) { return ; }
77
77
for_obj = full_obj_path[ TypeResolver :: generated_container_path ( ) . len ( ) + 2 ..] . into ( ) ;
78
78
}
79
79
@@ -366,9 +366,6 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
366
366
writeln ! ( extra_headers, "struct LDK{};" , trait_name) . unwrap ( ) ;
367
367
continue ;
368
368
}
369
- // Sadly, this currently doesn't do what we want, but it should be easy to get
370
- // cbindgen to support it. See https://github.com/eqrion/cbindgen/issues/531
371
- writeln ! ( w, "\t #[must_use]" ) . unwrap ( ) ;
372
369
}
373
370
374
371
let mut cpp_docs = Vec :: new ( ) ;
@@ -535,7 +532,12 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
535
532
syn:: TypeParamBound :: Trait ( tr) => {
536
533
writeln!( w, "\t type {} = crate::{};" , t. ident, $type_resolver. resolve_path( & tr. path, Some ( & gen_types) ) ) . unwrap( ) ;
537
534
for bound in bounds_iter {
538
- 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
+ }
539
541
}
540
542
break ;
541
543
} ,
@@ -803,7 +805,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
803
805
define_field ! ( ( 'a' as u8 + idx as u8 ) as char , ( '0' as u8 + idx as u8 ) as char , field) ;
804
806
}
805
807
}
806
- _ => unimplemented ! ( )
808
+ syn :: Fields :: Unit => { } ,
807
809
}
808
810
809
811
if all_fields_settable {
@@ -826,7 +828,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
826
828
types. write_c_type ( w, & field. ty , Some ( & gen_types) , false ) ;
827
829
}
828
830
}
829
- _ => unreachable ! ( )
831
+ syn :: Fields :: Unit => { } ,
830
832
}
831
833
write ! ( w, ") -> {} {{\n \t " , struct_name) . unwrap ( ) ;
832
834
match & s. fields {
@@ -846,7 +848,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
846
848
}
847
849
}
848
850
} ,
849
- _ => unreachable ! ( )
851
+ syn :: Fields :: Unit => { } ,
850
852
}
851
853
write ! ( w, "{} {{ inner: ObjOps::heap_alloc(" , struct_name) . unwrap ( ) ;
852
854
match & s. fields {
@@ -874,7 +876,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
874
876
}
875
877
write ! ( w, "\t )" ) . unwrap ( ) ;
876
878
} ,
877
- _ => unreachable ! ( )
879
+ syn :: Fields :: Unit => write ! ( w , "{}::{} {{}}" , types . module_path , struct_name ) . unwrap ( ) ,
878
880
}
879
881
writeln ! ( w, "), is_owned: true }}\n }}" ) . unwrap ( ) ;
880
882
}
@@ -943,9 +945,11 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
943
945
if i. defaultness . is_some ( ) || i. unsafety . is_some ( ) { unimplemented ! ( ) ; }
944
946
if let Some ( trait_path) = i. trait_ . as_ref ( ) {
945
947
if trait_path. 0 . is_some ( ) { unimplemented ! ( ) ; }
946
- if types. understood_c_path ( & trait_path. 1 ) {
947
- let full_trait_path = types. resolve_path ( & trait_path. 1 , None ) ;
948
- let trait_obj = * types. crate_types . traits . get ( & full_trait_path) . unwrap ( ) ;
948
+ let full_trait_path_opt = types. maybe_resolve_path ( & trait_path. 1 , None ) ;
949
+ let trait_obj_opt = full_trait_path_opt. as_ref ( ) . and_then ( |path| types. crate_types . traits . get ( path) ) ;
950
+ if types. understood_c_path ( & trait_path. 1 ) && trait_obj_opt. is_some ( ) {
951
+ let full_trait_path = full_trait_path_opt. unwrap ( ) ;
952
+ let trait_obj = * trait_obj_opt. unwrap ( ) ;
949
953
950
954
let supertrait_name;
951
955
let supertrait_resolver;
@@ -2198,9 +2202,13 @@ fn walk_private_mod<'a>(ast_storage: &'a FullLibraryAST, orig_crate: &str, modul
2198
2202
if let Some ( trait_path) = i. trait_ . as_ref ( ) {
2199
2203
if let Some ( tp) = import_resolver. maybe_resolve_path ( & trait_path. 1 , None ) {
2200
2204
if let Some ( sp) = import_resolver. maybe_resolve_path ( & p. path , None ) {
2201
- match crate_types. trait_impls . entry ( sp) {
2202
- hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( tp) ; } ,
2203
- hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ tp] ) ; } ,
2205
+ match crate_types. trait_impls . entry ( sp. clone ( ) ) {
2206
+ hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( tp. clone ( ) ) ; } ,
2207
+ hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ tp. clone( ) ] ) ; } ,
2208
+ }
2209
+ match crate_types. traits_impld . entry ( tp) {
2210
+ hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( sp) ; } ,
2211
+ hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ sp] ) ; } ,
2204
2212
}
2205
2213
}
2206
2214
}
@@ -2310,9 +2318,13 @@ fn walk_ast_first_pass<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut Cr
2310
2318
}
2311
2319
if let Some ( tp) = import_resolver. maybe_resolve_path ( & trait_path. 1 , None ) {
2312
2320
if let Some ( sp) = import_resolver. maybe_resolve_path ( & p. path , None ) {
2313
- match crate_types. trait_impls . entry ( sp) {
2314
- hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( tp) ; } ,
2315
- hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ tp] ) ; } ,
2321
+ match crate_types. trait_impls . entry ( sp. clone ( ) ) {
2322
+ hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( tp. clone ( ) ) ; } ,
2323
+ hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ tp. clone( ) ] ) ; } ,
2324
+ }
2325
+ match crate_types. traits_impld . entry ( tp) {
2326
+ hash_map:: Entry :: Occupied ( mut e) => { e. get_mut ( ) . push ( sp) ; } ,
2327
+ hash_map:: Entry :: Vacant ( e) => { e. insert ( vec ! [ sp] ) ; } ,
2316
2328
}
2317
2329
}
2318
2330
}
0 commit comments