Skip to content

Commit f307531

Browse files
committed
Reduce usage of last statement spans in proc-macros
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.
1 parent 992a168 commit f307531

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

tokio-macros/src/entry.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,20 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To
383383

384384
let body = &input.block;
385385
let brace_token = input.block.brace_token;
386-
input.block = syn::parse2(quote_spanned! {last_stmt_end_span=>
386+
let block_expr = quote_spanned! {last_stmt_end_span=>
387+
#[allow(clippy::expect_used, clippy::diverging_sub_expression)]
388+
{
389+
return #rt
390+
.enable_all()
391+
.build()
392+
.expect("Failed building the Runtime")
393+
.block_on(body);
394+
}
395+
};
396+
input.block = syn::parse2(quote! {
387397
{
388398
let body = async #body;
389-
#[allow(clippy::expect_used, clippy::diverging_sub_expression)]
390-
{
391-
return #rt
392-
.enable_all()
393-
.build()
394-
.expect("Failed building the Runtime")
395-
.block_on(body);
396-
}
399+
#block_expr
397400
}
398401
})
399402
.expect("Parsing failure");

0 commit comments

Comments
 (0)