Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros: fix span of body variable #5244

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tokio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To

let body = &input.block;
let brace_token = input.block.brace_token;
let body_ident = quote! { body };
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);
.block_on(#body_ident);
}
};

Expand Down Expand Up @@ -479,7 +480,7 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool)
};
let config = if let Some(attr) = input.attrs.iter().find(|attr| attr.path.is_ident("test")) {
let msg = "second test attribute is supplied";
Err(syn::Error::new_spanned(&attr, msg))
Err(syn::Error::new_spanned(attr, msg))
} else {
AttributeArgs::parse_terminated
.parse(args)
Expand Down
15 changes: 15 additions & 0 deletions tokio/tests/macros_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ pub mod clippy_semicolon_if_nothing_returned {
// To trigger clippy::semicolon_if_nothing_returned lint, the block needs to contain newline.
}
}

// https://github.com/tokio-rs/tokio/issues/5243
pub mod issue_5243 {
macro_rules! mac {
(async fn $name:ident() $b:block) => {
#[::tokio::test]
async fn $name() {
$b
}
};
}
mac!(
async fn foo() {}
);
}