Skip to content
Prev Previous commit
Next Next commit
actually include :: between path segments
  • Loading branch information
mellowagain committed Jul 3, 2023
commit ab9d382883e79d67cdc5f529c84949934ae6c3ca
19 changes: 13 additions & 6 deletions autometrics-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre
Type::ImplTrait(_) => quote! {},
Type::Path(path) => {
let mut ts = vec![];
let mut first = true;

for segment in &path.path.segments {
let ident = &segment.ident;
Expand Down Expand Up @@ -127,11 +128,20 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre
});
}

quote! { <#(#ts),*> }
quote! { ::<#(#ts),*> }
}
_ => quote! {},
};

// primitive way to check whenever this is the first iteration or not
// as on the first iteration, we don't want to prepend `::`,
// as types may be local and/or imported and then couldn't be found
if !first {
ts.push(quote! { :: });
} else {
first = false;
}

ts.push(quote! { #ident });
ts.push(quote! { #suffix });
}
Expand Down Expand Up @@ -244,7 +254,7 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre
quote! {}
};

let a = quote! {
Ok(quote! {
#(#attrs)*

// Append the metrics documentation to the end of the function's documentation
Expand Down Expand Up @@ -280,10 +290,7 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre

result
}
};

//panic!("{}", a);
Ok(a)
})
}

/// Add autometrics instrumentation to an entire impl block
Expand Down