Move overly-specific check to an assertion where its relevant
[ldk-c-bindings] / c-bindings-gen / src / types.rs
index 2ea9221a63f6a6a22a76c01b93e9a0d29ae92db3..c96a3b9a2fd51220057d89381c95e77e2f5d11a6 100644 (file)
@@ -227,12 +227,13 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                                non_lifetimes_processed = true;
                                                                if path != "std::ops::Deref" && path != "core::ops::Deref" {
                                                                        new_typed_generics.insert(&type_param.ident, Some(path));
-                                                               } else if trait_bound.path.segments.len() == 1 {
+                                                               } else {
                                                                        // If we're templated on Deref<Target = ConcreteThing>, store
                                                                        // the reference type in `default_generics` which handles full
                                                                        // types and not just paths.
                                                                        if let syn::PathArguments::AngleBracketed(ref args) =
                                                                                        trait_bound.path.segments[0].arguments {
+                                                                               assert_eq!(trait_bound.path.segments.len(), 1);
                                                                                for subargument in args.args.iter() {
                                                                                        match subargument {
                                                                                                syn::GenericArgument::Lifetime(_) => {},
@@ -283,14 +284,12 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                                        non_lifetimes_processed = true;
                                                                        assert_simple_bound(&trait_bound);
                                                                        let resolved = types.resolve_path(&trait_bound.path, None);
-                                                                       let ref_ty = syn::Type::Reference(syn::TypeReference {
-                                                                               and_token: syn::Token![&](Span::call_site()),
-                                                                               lifetime: None, mutability: None,
-                                                                               elem: Box::new(syn::Type::Path(syn::TypePath {
-                                                                                       qself: None, path: string_path_to_syn_path(&resolved)
-                                                                               })),
+                                                                       let ty = syn::Type::Path(syn::TypePath {
+                                                                               qself: None, path: string_path_to_syn_path(&resolved)
                                                                        });
-                                                                       self.default_generics.insert(p_ident, (ref_ty.clone(), ref_ty));
+                                                                       let ref_ty = parse_quote!(&#ty);
+                                                                       self.default_generics.insert(p_ident, (ty, ref_ty));
+
                                                                        *gen = Some(resolved);
                                                                }
                                                        }