From: Matt Corallo Date: Thu, 11 Feb 2021 16:34:16 +0000 (-0500) Subject: [bindings] Allow resolution of private types in some cases X-Git-Tag: v0.0.13~27^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b49781e8d81dc400033c1ea6660f06eda9a87347;p=rust-lightning [bindings] Allow resolution of private types in some cases We need this specifically for resolving the features::sealed::Context trait which is inside the non-pub `sealed` module. --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 198e0cfdd..f8e5b4849 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -1165,9 +1165,12 @@ impl FullLibraryAST { }; self.load_module(modname, m.attrs, m.content.unwrap().1); submods.push(modident); + } else { + non_mod_items.push(syn::Item::Mod(m)); } } }, + syn::Item::Mod(_) => panic!("--pretty=expanded output should never have non-body modules"), _ => { non_mod_items.push(item); } } } diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index cba9407ae..afe719ffe 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -302,6 +302,7 @@ pub struct ImportResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> { module_path: &'mod_lifetime str, imports: HashMap, declared: HashMap>, + priv_modules: HashSet, } impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'crate_lft> { fn process_use_intern(imports: &mut HashMap, u: &syn::UseTree, partial_path: &str, mut path: syn::punctuated::Punctuated) { @@ -368,6 +369,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr Self::insert_primitive(&mut imports, "Option"); let mut declared = HashMap::new(); + let mut priv_modules = HashSet::new(); for item in contents.iter() { match item { @@ -395,11 +397,14 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr declared.insert(t.ident.clone(), DeclType::Trait(t)); } }, + syn::Item::Mod(m) => { + priv_modules.insert(m.ident.clone()); + }, _ => {}, } } - Self { module_path, imports, declared } + Self { module_path, imports, declared, priv_modules } } pub fn get_declared_type(&self, ident: &syn::Ident) -> Option<&DeclType<'crate_lft>> { @@ -458,6 +463,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr } else { Some(imp.clone()) } + } else if let Some(_) = self.priv_modules.get(&first_seg.ident) { + Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining)) } else { None } } }