Correct `use` resolution for submodule use statements
[ldk-c-bindings] / c-bindings-gen / src / types.rs
index 8cc7d1eaa501f3bfcf16d80ae15a655999a631ab..398d0241c61d3b10d524e37a602a5c0a3fc3e2aa 100644 (file)
@@ -474,9 +474,12 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
                                        let crate_name_ident = format_ident!("{}", crate_name);
                                        path.push(parse_quote!(#crate_name_ident));
                                } else if partial_path == "" && !dependencies.contains(&$ident) {
-                                       new_path = format!("{}::{}{}", crate_name, $ident, $path_suffix);
-                                       let crate_name_ident = format_ident!("{}", crate_name);
-                                       path.push(parse_quote!(#crate_name_ident));
+                                       new_path = format!("{}::{}{}", module_path, $ident, $path_suffix);
+                                       for module in module_path.split("::") {
+                                               path.push(syn::PathSegment { ident: syn::Ident::new(module, Span::call_site()), arguments: syn::PathArguments::None });
+                                       }
+                                       let ident_str = format_ident!("{}", $ident);
+                                       path.push(parse_quote!(#ident_str));
                                } else if format!("{}", $ident) == "self" {
                                        let mut path_iter = partial_path.rsplitn(2, "::");
                                        path_iter.next().unwrap();
@@ -814,6 +817,7 @@ fn initial_clonable_types() -> HashSet<String> {
        res.insert("crate::c_types::TxOut".to_owned());
        res.insert("crate::c_types::Signature".to_owned());
        res.insert("crate::c_types::RecoverableSignature".to_owned());
+       res.insert("crate::c_types::BigEndianScalar".to_owned());
        res.insert("crate::c_types::Bech32Error".to_owned());
        res.insert("crate::c_types::Secp256k1Error".to_owned());
        res.insert("crate::c_types::IOError".to_owned());
@@ -1624,7 +1628,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                                        let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap();
                                                        return Some(("if ", vec![
                                                                (format!(".is_none() {{ {}::None }} else {{ {}::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */", inner_name, inner_name),
-                                                                format!("{}.clone().unwrap()", var_access))
+                                                                format!("(*{}.as_ref().unwrap()).clone()", var_access))
                                                                ], ") }", ContainerPrefixLocation::PerConv));
                                                }
                                        } else {