jni-bridge: forward attributes onto the generated JNI function
- Commit
3ae7f7260279358c2bc535d9d301e1c2a3d9c54b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 19:16 UTC (4 days ago)
- Parents
e22742f
jni_fn! now accepts attributes before the exported name and re-emits them on the generated function. Several JNI surfaces carry #[allow(clippy::too_many_arguments)] on their hand-written functions; without forwarding, that attribute would land on the macro invocation, where it is ignored and warned about, and the lint it suppresses would be lost. Existing invocations are unaffected (the attribute list is optional and empty for them); the office pilot's expansion is unchanged. Verified with cargo test -p jni_bridge and by the pdf_render conversion that follows, whose nine allow attributes now reach the generated functions with no unused-attribute warnings and an identical exported symbol set.
Diff
library/jni-bridge/src/main/rust/src/lib.rs
diff --git a/library/jni-bridge/src/main/rust/src/lib.rs b/library/jni-bridge/src/main/rust/src/lib.rsindex 263214e68e..ff4cb81758 100644--- a/library/jni-bridge/src/main/rust/src/lib.rs+++ b/library/jni-bridge/src/main/rust/src/lib.rs@@ -46,12 +46,16 @@ pub use jni; /// Void form (no `-> Ret`): the body evaluates to `Result<()>` and the /// generated method returns nothing. ///+/// Attributes written before the name (e.g. `#[allow(clippy::…)]`) are+/// forwarded onto the generated function.+/// /// The lifetime `'l` is the JNI frame lifetime introduced by the generated /// function; argument types such as `JString<'l>` refer to it, as in the /// hand-written form. #[macro_export] macro_rules! jni_fn {- ($name:ident -> $ret:ty; ($($arg:ident: $arg_ty:ty),* $(,)?) |$env:ident| $body:block) => {+ ($(#[$attr:meta])* $name:ident -> $ret:ty; ($($arg:ident: $arg_ty:ty),* $(,)?) |$env:ident| $body:block) => {+ $(#[$attr])* #[no_mangle] pub extern "system" fn $name<'l>( mut env: $crate::jni::EnvUnowned<'l>,@@ -61,7 +65,8 @@ macro_rules! jni_fn { .resolve::<$crate::jni::errors::LogErrorAndDefault>() } };- ($name:ident; ($($arg:ident: $arg_ty:ty),* $(,)?) |$env:ident| $body:block) => {+ ($(#[$attr:meta])* $name:ident; ($($arg:ident: $arg_ty:ty),* $(,)?) |$env:ident| $body:block) => {+ $(#[$attr])* #[no_mangle] pub extern "system" fn $name<'l>( mut env: $crate::jni::EnvUnowned<'l>,