From: Matt Corallo Date: Sat, 28 May 2022 01:06:56 +0000 (+0000) Subject: Support `use ...::self` imports X-Git-Tag: v0.0.108.0^2~27 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=e6b040d51589d726cb506830e2b0e0363f411634;p=ldk-c-bindings Support `use ...::self` imports Previously we'd supported `use self:...` but this adds support for using some path that ends with `self`. --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 772c34b..c532b81 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -438,6 +438,10 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr new_path = format!("{}::{}{}", crate_name, $ident, $path_suffix); let crate_name_ident = format_ident!("{}", crate_name); path.push(parse_quote!(#crate_name_ident)); + } else if format!("{}", $ident) == "self" { + let mut path_iter = partial_path.rsplitn(2, "::"); + path_iter.next().unwrap(); + new_path = path_iter.next().unwrap().to_owned(); } else { new_path = format!("{}{}{}", partial_path, $ident, $path_suffix); } @@ -452,7 +456,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr }, syn::UseTree::Name(n) => { push_path!(n.ident, ""); - imports.insert(n.ident.clone(), (new_path, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path })); + let imported_ident = syn::Ident::new(new_path.rsplitn(2, "::").next().unwrap(), Span::call_site()); + imports.insert(imported_ident, (new_path, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path })); }, syn::UseTree::Group(g) => { for i in g.items.iter() {