{"record":{"id":"1c3079bd0c4216a2","repo":"tokio-rs/tokio","slug":"the-tokio-test-macro-requires-rt-or-rt-multi-t","errorCode":null,"errorMessage":"The #[tokio::test] macro requires rt or rt-multi-thread.","messagePattern":"The #\\[tokio::test\\] macro requires rt or rt-multi-thread\\.","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"tokio-macros/src/lib.rs","lineNumber":648,"sourceCode":"#[proc_macro_attribute]\npub fn main_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {\n    syn::Error::new(\n        proc_macro2::Span::call_site(),\n        \"The #[tokio::main] macro requires rt or rt-multi-thread.\",\n    )\n    .to_compile_error()\n    .into()\n}\n\n/// Always fails with the error message below.\n/// ```text\n/// The #[tokio::test] macro requires rt or rt-multi-thread.\n/// ```\n#[proc_macro_attribute]\npub fn test_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {\n    syn::Error::new(\n        proc_macro2::Span::call_site(),\n        \"The #[tokio::test] macro requires rt or rt-multi-thread.\",\n    )\n    .to_compile_error()\n    .into()\n}\n\n/// Implementation detail of the `select!` macro. This macro is **not** intended\n/// to be used as part of the public API and is permitted to change.\n#[proc_macro]\n#[doc(hidden)]\npub fn select_priv_declare_output_enum(input: TokenStream) -> TokenStream {\n    select::declare_output_enum(input)\n}\n\n/// Implementation detail of the `select!` macro. This macro is **not** intended\n/// to be used as part of the public API and is permitted to change.\n#[proc_macro]\n#[doc(hidden)]\npub fn select_priv_clean_pattern(input: TokenStream) -> TokenStream {","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio-macros/src/lib.rs#L630-L666","documentation":"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.","triggerScenarios":"Annotating `#[tokio::test]` on an async test while `tokio` lacks both `rt` and `rt-multi-thread` features.","commonSituations":"Dev/test dependency declared as `tokio = { version = \"...\", features = [\"macros\"] }` only; `default-features = false` minus `rt`; shared workspace dependency template that omits the runtime feature.","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."],"exampleFix":"# before\ntokio = { version = \"1\", features = [\"macros\"] }\n\n# after\ntokio = { version = \"1\", features = [\"rt\", \"macros\"] }","handlingStrategy":"validation","validationCode":"// Verify the test build resolves an rt feature:\n// `cargo tree -e features -p tokio --target-host | grep -E '\\b(rt|rt-multi-thread)\\b'`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["rust","tokio","macros","features","compile-time","testing"],"backgroundTag":null,"analyzedSha":"625954f365727668cb02d04172b34f1149637728","analyzedAt":"2026-08-11T17:46:45.378Z","contentChangedAt":"2026-08-11T17:46:45.378Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}