Skip to content

Commit

Permalink
attr names
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
  • Loading branch information
yoshuawuyts committed Jun 28, 2019
1 parent ba1b99e commit 216dcde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
18 changes: 5 additions & 13 deletions async-log-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use quote::quote;
/// Ok(())
/// }
/// ```
#[cfg(not(test))] // NOTE: exporting main breaks tests, we should file an issue.
#[proc_macro_attribute]
pub fn span_wrap(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
Expand Down Expand Up @@ -50,25 +49,18 @@ pub fn span_wrap(_attr: TokenStream, item: TokenStream) -> TokenStream {
let names: String = args
.iter()
.enumerate()
.map(|(i, _arg)| match i {
0 => {
let mut string = format!("arg_{}", 0);
string.push_str("={}");
string
}
n => {
let mut string = format!(", arg_{}", n);
string.push_str("={}");
string
}
.map(|(i, _arg)| {
let mut string = format!(", arg_{}", i);
string.push_str("={}");
string
})
.collect();

let result = quote! {
#(#attrs)*
#vis #constness #unsafety #asyncness #abi fn #generics #name(#(#inputs)*) #output {
let __name = format!("{}#{}", file!(), stringify!(#name));
let __args = format!("{} {}", __name, format_args!(#names, #(#args)*));
let __args = format!("{}{}", __name, format_args!(#names, #(#args)*));
async_log::span!(__args, {
#(#body)*
})
Expand Down
1 change: 1 addition & 0 deletions src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) struct Symbol {
///
/// `depth` is how many frames we should look past finding the method where this was called.
/// This might require a bit of wrangling to find.
#[allow(unused_attributes)]
#[no_mangle]
pub(crate) fn async_log_capture_caller(depth: u8) -> Option<Symbol> {
let mut count = 0;
Expand Down

0 comments on commit 216dcde

Please # to comment.