From: Matt Corallo Date: Wed, 22 Sep 2021 18:39:46 +0000 (+0000) Subject: Correct printing generic methods in traits X-Git-Tag: v0.0.101.1~1^2~16 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bf77ececa4ed93dd954c13d59ad2c14f10710586;p=ldk-c-bindings Correct printing generic methods in traits If a trait method is generic (and not the object itself), we previously would print the concrete resolved types in the `impl nativeTrait for TraitStruct` block instead of the generic names, leading to compilation failures. --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index a114c22..1572b31 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -402,8 +402,11 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty } let mut meth_gen_types = gen_types.push_ctx(); assert!(meth_gen_types.learn_generics(&m.sig.generics, $type_resolver)); + // Note that we do *not* use the method generics when printing "native" + // rust parts - if the method is generic, we need to print a generic + // method. write!(w, "\tfn {}", m.sig.ident).unwrap(); - $type_resolver.write_rust_generic_param(w, Some(&meth_gen_types), m.sig.generics.params.iter()); + $type_resolver.write_rust_generic_param(w, Some(&gen_types), m.sig.generics.params.iter()); write!(w, "(").unwrap(); for inp in m.sig.inputs.iter() { match inp { @@ -431,7 +434,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty } _ => unimplemented!(), } - $type_resolver.write_rust_type(w, Some(&meth_gen_types), &*arg.ty); + $type_resolver.write_rust_type(w, Some(&gen_types), &*arg.ty); } } } @@ -439,7 +442,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty match &m.sig.output { syn::ReturnType::Type(_, rtype) => { write!(w, " -> ").unwrap(); - $type_resolver.write_rust_type(w, Some(&meth_gen_types), &*rtype) + $type_resolver.write_rust_type(w, Some(&gen_types), &*rtype) }, _ => {}, }