]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Use resolved, not local ident in generic mangling
authorMatt Corallo <git@bluematt.me>
Sat, 6 Feb 2021 04:26:53 +0000 (23:26 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 18 Feb 2021 17:28:25 +0000 (12:28 -0500)
In traits with associated types which are returned in generics (ie
`trait T { type A: B; fn c() -> Result<Self::A, ()> {} }`), 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.

c-bindings-gen/src/types.rs

index 75995b8435f1fcc65b66247be292798897c86351..ed88c502a199e8e9b018ef78697c0fa193f91934 100644 (file)
@@ -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<u8>> {