From 73e7582a0710a601174e8357992d8dc855b641e5 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 9 Feb 2021 15:53:51 -0800 Subject: [PATCH] attributes: remove closure type annotation in `#[instrument(err)]` Currently, using `#[instrument(err)]` on a function returning a `Result` with an `impl Trait` in it results in a compiler error. This is because we generate a type annotation on the closure in the function body that contains the user function's actual body, and `impl Trait` isn't allowed on types in local bindings, only on function parameters and return types. This branch fixes the issue by simply removing the return type annotation from the closure. I've also added tests that break on master for functions returning `impl Trait`, both with and without the `err` argument. Fixes #1227 Signed-off-by: Eliza Weisman --- tracing-attributes/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-attributes/src/lib.rs b/tracing-attributes/src/lib.rs index 2db896b2c9..b692d11d47 100644 --- a/tracing-attributes/src/lib.rs +++ b/tracing-attributes/src/lib.rs @@ -469,7 +469,7 @@ fn gen_body( quote_spanned!(block.span()=> let __tracing_attr_span = #span; let __tracing_attr_guard = __tracing_attr_span.enter(); - match move || #return_type #block () { + match (move || #block)() { #[allow(clippy::unit_arg)] Ok(x) => Ok(x), Err(e) => {