Skip to content

Commit 213598d

Browse files
committed
macros: don't emit additional warnings when checks fail
1 parent 3a29832 commit 213598d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tokio-macros/src/entry.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,14 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
422422
};
423423

424424
let mut checks = vec![];
425+
let mut attrs = vec![];
425426

426427
let build = if let RuntimeFlavor::Local = config.flavor {
427428
checks.push(quote! {
428429
#[cfg(not(tokio_unstable))]
429430
compile_error!("The local runtime flavor is only available when `tokio_unstable` is set.");
430431
});
432+
attrs.push(quote! { #[cfg(tokio_unstable)] });
431433
quote_spanned! {last_stmt_start_span=> build_local(Default::default())}
432434
} else {
433435
quote_spanned! {last_stmt_start_span=> build()}
@@ -455,15 +457,21 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
455457
let body_ident = quote! { body };
456458
// This explicit `return` is intentional. See tokio-rs/tokio#4636
457459
let last_block = quote_spanned! {last_stmt_end_span=>
460+
#(#checks)*
461+
#(#attrs)*
458462
#[allow(clippy::expect_used, clippy::diverging_sub_expression, clippy::needless_return)]
459463
{
460-
#(#checks)*
461464
return #rt
462465
.enable_all()
463466
.#build
464467
.expect("Failed building the Runtime")
465468
.block_on(#body_ident);
466469
}
470+
471+
#[allow(unreachable_code)]
472+
{
473+
panic!("fell through checks")
474+
}
467475
};
468476

469477
let body = input.body();

0 commit comments

Comments
 (0)