Generate `mod detail` and assertions outside of the namespace module
We can now do this because we now use qualified identifiers
PiperOrigin-RevId: 447960552
diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs
index 17092a6..3eb09de 100644
--- a/rs_bindings_from_cc/src_code_gen.rs
+++ b/rs_bindings_from_cc/src_code_gen.rs
@@ -1308,21 +1308,12 @@
let name = make_rs_ident(&namespace.name.identifier);
- // TODO(rosica): Instead of generating thunks and assertions within
- // the namespace, we could put them at the end of the file.
- // For this we need to have fully qualified identifiers.
- let mod_detail = if thunks.is_empty() {
- quote! {}
- } else {
- quote! {
- mod detail {
- #[allow(unused_imports)]
- use super::*;
- extern "C" {
- #( #thunks )*
- }
- }
- }
+ let thunks_tokens = quote! {
+ #( #thunks )*
+ };
+
+ let assertions_tokens = quote! {
+ #( #assertions )*
};
let namespace_tokens = quote! {
@@ -1330,12 +1321,6 @@
use super::*; __NEWLINE__ __NEWLINE__
#( #items __NEWLINE__ __NEWLINE__ )*
-
- __NEWLINE__ __NEWLINE__
- #mod_detail __NEWLINE__ __NEWLINE__
-
- #( #assertions __NEWLINE__ __NEWLINE__ )*
-
}
};
@@ -1343,6 +1328,8 @@
item: namespace_tokens,
features: features,
has_record: has_record,
+ thunks: thunks_tokens,
+ assertions: assertions_tokens,
..Default::default()
})
}
@@ -5195,7 +5182,7 @@
}
#[test]
- fn test_namespace_module_contains_detail() -> Result<()> {
+ fn test_detail_outside_of_namespace_module() -> Result<()> {
let rs_api = generate_bindings_tokens(&ir_from_cc(
r#"
namespace test_namespace_bindings {
@@ -5209,23 +5196,24 @@
quote! {
pub mod test_namespace_bindings {
...
- mod detail {
- #[allow(unused_imports)]
- use super::*;
- extern "C" {
- #[link_name = "_ZN23test_namespace_bindings1fEv"]
- pub(crate) fn __rust_thunk___ZN23test_namespace_bindings1fEv() -> i32;
- }
- }
- ...
}
+ ...
+ mod detail {
+ #[allow(unused_imports)]
+ use super::*;
+ extern "C" {
+ #[link_name = "_ZN23test_namespace_bindings1fEv"]
+ pub(crate) fn __rust_thunk___ZN23test_namespace_bindings1fEv() -> i32;
+ }
+ }
+ ...
}
);
Ok(())
}
#[test]
- fn test_namespace_module_contains_assertions() -> Result<()> {
+ fn test_assertions_outside_of_namespace_module() -> Result<()> {
let rs_api = generate_bindings_tokens(&ir_from_cc(
r#"
namespace test_namespace_bindings {
@@ -5240,13 +5228,13 @@
rs_api,
quote! {
pub mod test_namespace_bindings {
- use super::*;
...
- const _: () = assert!(rust_std::mem::size_of::<crate::test_namespace_bindings::S>() == 4usize);
- const _: () = assert!(rust_std::mem::align_of::<crate::test_namespace_bindings::S>() == 4usize);
- ...
- const _: () = assert!(offset_of!(crate::test_namespace_bindings::S, i) * 8 == 0usize);
}
+ ...
+ const _: () = assert!(rust_std::mem::size_of::<crate::test_namespace_bindings::S>() == 4usize);
+ const _: () = assert!(rust_std::mem::align_of::<crate::test_namespace_bindings::S>() == 4usize);
+ ...
+ const _: () = assert!(offset_of!(crate::test_namespace_bindings::S, i) * 8 == 0usize);
}
);
Ok(())