From 37d1d09d4a5c071e3f4193c8ecd280124a4c0fe6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 14 Oct 2022 09:50:09 +0200 Subject: [PATCH] macros: reduce usage of last statement spans in proc-macros (#5092) This excludes the initial let statement of the proc-macro expansion from receiving the last statement spans to aid completions in rust-analyzer. The current span confuses rust-analyzer as it will map the tail expression tokens to the let keyword (as this is the first token it finds with the same span) which currently breaks completions. This commit should not degrade the initial intent of the span reusages, as the type mismatch parts are still spanned appropriately. --- tokio-macros/src/entry.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 68eb82917..19cb0b1cc 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -383,17 +383,20 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To let body = &input.block; let brace_token = input.block.brace_token; - input.block = syn::parse2(quote_spanned! {last_stmt_end_span=> + let block_expr = quote_spanned! {last_stmt_end_span=> + #[allow(clippy::expect_used, clippy::diverging_sub_expression)] + { + return #rt + .enable_all() + .build() + .expect("Failed building the Runtime") + .block_on(body); + } + }; + input.block = syn::parse2(quote! { { let body = async #body; - #[allow(clippy::expect_used, clippy::diverging_sub_expression)] - { - return #rt - .enable_all() - .build() - .expect("Failed building the Runtime") - .block_on(body); - } + #block_expr } }) .expect("Parsing failure");