Skip to content

Commit 44a31b1

Browse files
committed
tokio-macros: emit compile error on local without unstable
1 parent b040de5 commit 44a31b1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tokio-macros/src/entry.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ impl Configuration {
180180

181181
let flavor = self.flavor.unwrap_or(self.default_flavor);
182182

183-
if flavor == F::Local && !cfg!(tokio_unstable) {
184-
let msg = "The local runtime flavor is only available when `tokio_unstable` is set."
185-
.to_string();
186-
return Err(syn::Error::new(Span::call_site(), msg));
187-
}
188-
189183
let worker_threads = match (flavor, self.worker_threads) {
190184
(F::CurrentThread | F::Local, Some((_, worker_threads_span))) => {
191185
let msg = format!(
@@ -427,7 +421,13 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
427421
},
428422
};
429423

424+
let mut checks = vec![];
425+
430426
let build = if let RuntimeFlavor::Local = config.flavor {
427+
checks.push(quote! {
428+
#[cfg(not(tokio_unstable))]
429+
compile_error!("The local runtime flavor is only available when `tokio_unstable` is set.");
430+
});
431431
quote_spanned! {last_stmt_start_span=> build_local(Default::default())}
432432
} else {
433433
quote_spanned! {last_stmt_start_span=> build()}
@@ -457,6 +457,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
457457
let last_block = quote_spanned! {last_stmt_end_span=>
458458
#[allow(clippy::expect_used, clippy::diverging_sub_expression, clippy::needless_return)]
459459
{
460+
#(#checks)*
460461
return #rt
461462
.enable_all()
462463
.#build

0 commit comments

Comments
 (0)