]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Include the `where` clause from a "real" type when mapping type aliases
authorMatt Corallo <git@bluematt.me>
Mon, 30 May 2022 23:51:54 +0000 (23:51 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 28 Jun 2022 16:52:23 +0000 (16:52 +0000)
ie if we have a
```
struct A<T: Deref> where T::Target: Trait {}
pub type B<T> = A<T>;
```

this includes the `where` clause so that we end up calling
`writeln_opaque` for `struct B<T: Deref> where T::Target: Trait {}`
instead of `struct B<T: Deref> {}`.

c-bindings-gen/src/main.rs

index 37b64a8574b06f77d1dc7333d69db2c7bc1e23c1..bdd65e23c3b983c5301e15a14a62c0fcae187807 100644 (file)
@@ -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 {