Commit b725829c authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

Don't support async functions

It doesn't make sense to time async functions right now. Maybe something could
be devised for async functions in the future (ah. ah.), but right now this would
just be misleading.
parent 618ffffdfe3e
......@@ -19,6 +19,13 @@ use syn::spanned::Spanned;
/// #[timed] // Can only be used on functions
/// struct Thing;
/// ```
///
/// ```compile_fail
/// use micro_timer::timed;
///
/// #[timed] // Can only be used on sync functions
/// async fn func() {}
/// ```
#[proc_macro_attribute]
pub fn timed(
attrs: proc_macro::TokenStream,
......@@ -75,7 +82,16 @@ fn inner_timed(_attr_ts: TokenStream, fn_ts: TokenStream) -> TokenStream {
fn parse_function(item: syn::Item) -> Result<syn::ItemFn, TokenStream> {
match item {
syn::Item::Fn(func) => Ok(func),
syn::Item::Fn(func) => {
if func.sig.asyncness.is_some() {
return Err(quote_spanned! {
func.span()=>
compile_error!("Cannot use `#[timed]` on async functions")
#func
});
}
Ok(func)
}
i => Err(quote_spanned! {
i.span()=>
compile_error!("`#[timed]` can only be used on functions");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment