extern crate proc_macro; extern crate quote; extern crate syn; use { proc_macro::TokenStream, quote::quote, syn::{parse_macro_input, ItemFn} }; #[proc_macro_attribute] pub fn ktest(_attr: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as ItemFn); let test_name = &input.sig.ident; let static_var_name = syn::Ident::new( &format!("__ktest_{}", test_name), test_name.span(), ); let out = quote! { // #[cfg(feature = "ktest")] #input // #[cfg(feature = "ktest")] #[unsafe(link_section = ".note.ktest")] #[used] pub static #static_var_name: fn() = #test_name; }; TokenStream::from(out) }