From: Matt Corallo Date: Sat, 6 Feb 2021 04:26:53 +0000 (-0500) Subject: [bindings] Use resolved, not local ident in generic mangling X-Git-Tag: v0.0.13~27^2~14 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=9e596e24600b4ea660ca4d9a92e7923d48738b0b;p=rust-lightning [bindings] Use resolved, not local ident in generic mangling In traits with associated types which are returned in generics (ie `trait T { type A: B; fn c() -> Result {} }`), we created a new generic mapping with the local type name (in this case A) instead of using the real type (in this case B). This is confusing as it results in generic manglings that don't reference the real type (eg `LDKCResult_ChanKeySignerDecodeErrorZ`) and may have multiple generic definitions that are identical. Instead, we now use the final ident in the resolved mapping. The biggest win is `LDKCResult_ChanKeySignerDecodeErrorZ` changing to `CResult_ChannelKeysDecodeErrorZ`. However, there are several types where `secp256k1::Error` was imported as `SecpError` and types like `LDKCResult_SecretKeySecpErrorZ` are now `LDKCResult_SecretKeyErrorZ` instead. Still, the type of the error field remains `LDKSecp256k1Error`, which should avoid any confusion. --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 75995b84..ed88c502 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -1878,7 +1878,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { generics, &subtype, is_ref, is_mut, ptr_for_ref, true); } } else { - let id = &&$p_arg.path.segments.iter().rev().next().unwrap().ident; + let id = subtype.rsplitn(2, ':').next().unwrap(); // Get the "Base" name of the resolved type write!(w, "{}", id).unwrap(); write!(mangled_type, "{}", id).unwrap(); if let Some(w2) = $extra_write as Option<&mut Vec> {