tokio-rs/tokio · error · syn::Error
The #[tokio::test] macro requires rt or rt-multi-thread.
Error message
The #[tokio::test] macro requires rt or rt-multi-thread.
What it means
Compile-time error from the `test_fail` proc-macro attribute, which Tokio aliases to `#[tokio::test]` when neither `rt` nor `rt-multi-thread` is enabled (always fails with this message). Mirrors `main_fail` for the test macro.
Source
Thrown at tokio-macros/src/lib.rs:648
#[proc_macro_attribute]
pub fn main_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::main] macro requires rt or rt-multi-thread.",
)
.to_compile_error()
.into()
}
/// Always fails with the error message below.
/// ```text
/// The #[tokio::test] macro requires rt or rt-multi-thread.
/// ```
#[proc_macro_attribute]
pub fn test_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::test] macro requires rt or rt-multi-thread.",
)
.to_compile_error()
.into()
}
/// Implementation detail of the `select!` macro. This macro is **not** intended
/// to be used as part of the public API and is permitted to change.
#[proc_macro]
#[doc(hidden)]
pub fn select_priv_declare_output_enum(input: TokenStream) -> TokenStream {
select::declare_output_enum(input)
}
/// Implementation detail of the `select!` macro. This macro is **not** intended
/// to be used as part of the public API and is permitted to change.
#[proc_macro]
#[doc(hidden)]
pub fn select_priv_clean_pattern(input: TokenStream) -> TokenStream {View on GitHub (pinned to 625954f365)
Solutions
- Add a runtime feature: `tokio = { version = "1", features = ["rt", "macros"] }` (or `rt-multi-thread`).
- Check `cargo tree -e features -p tokio` to verify the active features in the test build.
- If using `#[tokio::test(flavor = "multi_thread")]`, ensure `rt-multi-thread` is enabled.
Example fix
# before
tokio = { version = "1", features = ["macros"] }
# after
tokio = { version = "1", features = ["rt", "macros"] } Defensive patterns
Strategy: validation
Validate before calling
// Verify the test build resolves an rt feature: // `cargo tree -e features -p tokio --target-host | grep -E '\b(rt|rt-multi-thread)\b'`
Prevention
- Declare `tokio` for tests with at least `rt` (or `rt-multi-thread`) plus `macros`.
- Use `#[tokio::test(flavor = "multi_thread")]` only when `rt-multi-thread` is enabled.
- Keep a shared `[dev-dependencies]` template in the workspace.
When it happens
Trigger: Annotating `#[tokio::test]` on an async test while `tokio` lacks both `rt` and `rt-multi-thread` features.
Common situations: Dev/test dependency declared as `tokio = { version = "...", features = ["macros"] }` only; `default-features = false` minus `rt`; shared workspace dependency template that omits the runtime feature.
Related errors
- The #[tokio::main] macro requires rt or rt-multi-thread.
- Failed to parse value of `{field}` as integer.
- Failed to parse value of `{field}` as string.
- Failed to parse value of `{}` as path: "{}"
- Failed to parse value of `{field}` as path.
AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11).
Data as JSON: /api/errors/1c3079bd0c4216a2.
Report an issue: GitHub.