From 127a10d7c64fdacfe201fd192fd21b7a22575496 Mon Sep 17 00:00:00 2001 From: andylokandy Date: Thu, 20 Jun 2024 00:18:21 +0800 Subject: [PATCH] fix: correctly handle async --- Cargo.toml | 2 +- src/lib.rs | 8 ++++---- tests/ui/ok/minitrace.rs | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51b26b5..c749f5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "logcall" -version = "0.1.8" +version = "0.1.9" edition = "2021" authors = ["andylokandy "] description = "An attribute macro that logs the function return value." diff --git a/src/lib.rs b/src/lib.rs index f4ea04c..1298c08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,8 +187,7 @@ fn gen_block( #[allow(clippy::useless_format)] let __input_string = format!(#input_format); #[allow(unknown_lints)] - #[allow(clippy::redundant_closure_call)] - let __ret_value = (move || #block)(); + let __ret_value = async { #block }.await; #log; __ret_value ); @@ -211,6 +210,7 @@ fn gen_block( let __input_string = format!(#input_format); #[allow(unknown_lints)] #[allow(clippy::redundant_closure_call)] + #[allow(clippy::let_unit_value)] let __ret_value = (move || #block)(); #log; __ret_value @@ -258,8 +258,7 @@ fn gen_block( #[allow(clippy::useless_format)] let __input_string = format!(#input_format); #[allow(unknown_lints)] - #[allow(clippy::redundant_closure_call)] - let __ret_value = (move || #block)(); + let __ret_value = async { #block }.await; match __ret_value { #ok_arm #err_arm @@ -283,6 +282,7 @@ fn gen_block( let __input_string = format!(#input_format); #[allow(unknown_lints)] #[allow(clippy::redundant_closure_call)] + #[allow(clippy::let_unit_value)] let __ret_value = (move || #block)(); match __ret_value { #ok_arm diff --git a/tests/ui/ok/minitrace.rs b/tests/ui/ok/minitrace.rs index c666baf..588562e 100644 --- a/tests/ui/ok/minitrace.rs +++ b/tests/ui/ok/minitrace.rs @@ -4,7 +4,9 @@ fn f() {} #[logcall::logcall] #[minitrace::trace] -async fn g() {} +async fn g() { + std::future::ready(1).await; +} fn main() { f();