]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Add where-clause generic params to `default_generics` map
authorMatt Corallo <git@bluematt.me>
Wed, 22 Jun 2022 19:30:05 +0000 (19:30 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 28 Jun 2022 16:52:23 +0000 (16:52 +0000)
This moves yet more generic resolution to being able to rely on the
`default_generics` map for full-`Type` resolution rather than
string-based name resolution.

c-bindings-gen/src/types.rs

index c532b8136dcf7fe9203efe67e8016f203f413605..2ea9221a63f6a6a22a76c01b93e9a0d29ae92db3 100644 (file)
@@ -268,7 +268,8 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                if p.qself.is_some() { return false; }
                                                if p.path.leading_colon.is_some() { return false; }
                                                let mut p_iter = p.path.segments.iter();
-                                               if let Some(gen) = new_typed_generics.get_mut(&p_iter.next().unwrap().ident) {
+                                               let p_ident = &p_iter.next().unwrap().ident;
+                                               if let Some(gen) = new_typed_generics.get_mut(p_ident) {
                                                        if gen.is_some() { return false; }
                                                        if &format!("{}", p_iter.next().unwrap().ident) != "Target" {return false; }
 
@@ -281,7 +282,16 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                                        if non_lifetimes_processed { return false; }
                                                                        non_lifetimes_processed = true;
                                                                        assert_simple_bound(&trait_bound);
-                                                                       *gen = Some(types.resolve_path(&trait_bound.path, None));
+                                                                       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)
+                                                                               })),
+                                                                       });
+                                                                       self.default_generics.insert(p_ident, (ref_ty.clone(), ref_ty));
+                                                                       *gen = Some(resolved);
                                                                }
                                                        }
                                                } else { return false; }