Include the `where` clause from a "real" type when mapping type aliases
[ldk-c-bindings] / c-bindings-gen / src / main.rs
index 3814d57b3c335d984c60bd0ed31fe393ae8851cf..bdd65e23c3b983c5301e15a14a62c0fcae187807 100644 (file)
@@ -449,7 +449,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                if m.default.is_some() { unimplemented!(); }
                                                if m.sig.constness.is_some() || m.sig.asyncness.is_some() || m.sig.unsafety.is_some() ||
                                                                m.sig.abi.is_some() || m.sig.variadic.is_some() {
-                                                       unimplemented!();
+                                                       panic!("1");
                                                }
                                                let mut meth_gen_types = gen_types.push_ctx();
                                                assert!(meth_gen_types.learn_generics(&m.sig.generics, $type_resolver));
@@ -462,7 +462,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                for inp in m.sig.inputs.iter() {
                                                        match inp {
                                                                syn::FnArg::Receiver(recv) => {
-                                                                       if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); }
+                                                                       if !recv.attrs.is_empty() || recv.reference.is_none() { panic!("2"); }
                                                                        write!(w, "&").unwrap();
                                                                        if let Some(lft) = &recv.reference.as_ref().unwrap().1 {
                                                                                write!(w, "'{} ", lft.ident).unwrap();
@@ -474,16 +474,16 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                                        }
                                                                },
                                                                syn::FnArg::Typed(arg) => {
-                                                                       if !arg.attrs.is_empty() { unimplemented!(); }
+                                                                       if !arg.attrs.is_empty() { panic!("3"); }
                                                                        match &*arg.pat {
                                                                                syn::Pat::Ident(ident) => {
                                                                                        if !ident.attrs.is_empty() || ident.by_ref.is_some() ||
                                                                                                        ident.mutability.is_some() || ident.subpat.is_some() {
-                                                                                               unimplemented!();
+                                                                                               panic!("4");
                                                                                        }
                                                                                        write!(w, ", mut {}{}: ", if $type_resolver.skip_arg(&*arg.ty, Some(&meth_gen_types)) { "_" } else { "" }, ident.ident).unwrap();
                                                                                }
-                                                                               _ => unimplemented!(),
+                                                                               _ => panic!("5"),
                                                                        }
                                                                        $type_resolver.write_rust_type(w, Some(&gen_types), &*arg.ty);
                                                                }
@@ -500,7 +500,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                write!(w, " {{\n\t\t").unwrap();
                                                match export_status(&m.attrs) {
                                                        ExportStatus::NoExport => {
-                                                               unimplemented!();
+                                                               panic!("6");
                                                        },
                                                        _ => {},
                                                }
@@ -526,14 +526,14 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                writeln!(w, "\n\t}}").unwrap();
                                        },
                                        &syn::TraitItem::Type(ref t) => {
-                                               if t.default.is_some() || t.generics.lt_token.is_some() { unimplemented!(); }
+                                               if t.default.is_some() || t.generics.lt_token.is_some() { panic!("10"); }
                                                let mut bounds_iter = t.bounds.iter();
                                                loop {
                                                        match bounds_iter.next().unwrap() {
                                                                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 { unimplemented!(); }
+                                                                               if let syn::TypeParamBound::Trait(_) = bound { panic!("11"); }
                                                                        }
                                                                        break;
                                                                },
@@ -541,7 +541,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                        }
                                                }
                                        },
-                                       _ => unimplemented!(),
+                                       _ => panic!("12"),
                                }
                        }
                }
@@ -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 {