]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Allow resolution of private types in some cases
authorMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 16:34:16 +0000 (11:34 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 18:24:50 +0000 (13:24 -0500)
We need this specifically for resolving the
features::sealed::Context trait which is inside the non-pub
`sealed` module.

c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs

index 198e0cfdd3912b1e1d73b39be1b0a60ba32c46b2..f8e5b48492fd3944ca4775b7d593025f8ee79f0c 100644 (file)
@@ -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); }
                        }
                }
index cba9407ae1200b2b693cf7b8ac169b1b918b2e10..afe719ffe2ca11709f50f6942dbf629fc9920084 100644 (file)
@@ -302,6 +302,7 @@ pub struct ImportResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> {
        module_path: &'mod_lifetime str,
        imports: HashMap<syn::Ident, (String, syn::Path)>,
        declared: HashMap<syn::Ident, DeclType<'crate_lft>>,
+       priv_modules: HashSet<syn::Ident>,
 }
 impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'crate_lft> {
        fn process_use_intern(imports: &mut HashMap<syn::Ident, (String, syn::Path)>, u: &syn::UseTree, partial_path: &str, mut path: syn::punctuated::Punctuated<syn::PathSegment, syn::token::Colon2>) {
@@ -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 }
                }
        }