Skip to content

Commit

Permalink
macros: reduce usage of last statement spans in proc-macros (#5092)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Veykril committed Oct 14, 2022
1 parent 6929dec commit 37d1d09
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tokio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 37d1d09

Please sign in to comment.