Repository: dtolnay/cxx (language: rust)

Issue:
Support inner bridge mod
Currently we only find the #\[cxx::bridge\] invocation if it is at the top level of the Rust file passed as argument to the code generator. If it isn't at the top level, we fail with an error that looks like:

```console
cxxbridge: no #[cxx::bridge] module found
```

It would be good to also look for it inside of nested modules:

```rust
// lib.rs

pub fn ...

#[doc(hidden)]
mod details {
    #[cxx::bridge]
    mod ffi {
        ...
        ...
    }

    pub fn ...
}
```


Discussion / hints:

Fix patch:
diff --git a/gen/src/find.rs b/gen/src/find.rs
index dc83431ec..86e1dc7c3 100644
--- a/gen/src/find.rs
+++ b/gen/src/find.rs
@@ -4,7 +4,14 @@ use quote::quote;
 use syn::{Attribute, File, Item};
 
 pub(super) fn find_bridge_mod(syntax: File) -> Result<Input> {
-    for item in syntax.items {
+    match scan(syntax.items)? {
+        Some(input) => Ok(input),
+        None => Err(Error::NoBridgeMod),
+    }
+}
+
+fn scan(items: Vec<Item>) -> Result<Option<Input>> {
+    for item in items {
         if let Item::Mod(item) = item {
             for attr in &item.attrs {
                 let path = &attr.path;
@@ -19,12 +26,17 @@ pub(super) fn find_bridge_mod(syntax: File) -> Result<Input> {
                         }
                     };
                     let namespace = parse_args(attr)?;
-                    return Ok(Input { namespace, module });
+                    return Ok(Some(Input { namespace, module }));
+                }
+            }
+            if let Some(module) = item.content {
+                if let Some(input) = scan(module.1)? {
+                    return Ok(Some(input));
                 }
             }
         }
     }
-    Err(Error::NoBridgeMod)
+    Ok(None)
 }
 
 fn parse_args(attr: &Attribute) -> syn::Result<Namespace> {


Test patch: