From: Matt Corallo Date: Mon, 30 May 2022 23:51:54 +0000 (+0000) Subject: Include the `where` clause from a "real" type when mapping type aliases X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=d20bd908efc5c74d31c61dfc39660b8c62588687 Include the `where` clause from a "real" type when mapping type aliases ie if we have a ``` struct A where T::Target: Trait {} pub type B = A; ``` this includes the `where` clause so that we end up calling `writeln_opaque` for `struct B where T::Target: Trait {}` instead of `struct B {}`. --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 37b64a8..bdd65e2 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -1922,6 +1922,11 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a> type_resolver.crate_types.priv_structs.get(&real_ty).map(|r| *r)).unwrap(); let mut resolved_generics = t.generics.clone(); + // Assume blindly that the bounds in the struct definition where + // clause matches any equivalent bounds on the type alias. + assert!(resolved_generics.where_clause.is_none()); + resolved_generics.where_clause = real_generic_bounds.where_clause.clone(); + if let syn::PathArguments::AngleBracketed(real_generics) = &p.path.segments.last().unwrap().arguments { for (real_idx, real_param) in real_generics.args.iter().enumerate() { if let syn::GenericArgument::Type(syn::Type::Path(real_param_path)) = real_param {