{"record":{"id":"03c431d23bbb68fa","repo":"tokio-rs/tokio","slug":"the-tokio-main-macro-requires-rt-or-rt-multi-t","errorCode":null,"errorMessage":"The #[tokio::main] macro requires rt or rt-multi-thread.","messagePattern":"The #\\[tokio::main\\] macro requires rt or rt-multi-thread\\.","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"tokio-macros/src/lib.rs","lineNumber":634,"sourceCode":"/// #[tokio::test]\n/// async fn my_test() {\n///     assert!(true);\n/// }\n/// ```\n#[proc_macro_attribute]\npub fn test_rt(args: TokenStream, item: TokenStream) -> TokenStream {\n    entry::test(args.into(), item.into(), false).into()\n}\n\n/// Always fails with the error message below.\n/// ```text\n/// The #[tokio::main] macro requires rt or rt-multi-thread.\n/// ```\n#[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}","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio-macros/src/lib.rs#L616-L652","documentation":"Compile-time error from the `main_fail` proc-macro attribute, which Tokio aliases to `#[tokio::main]` when neither the `rt` nor `rt-multi-thread` Cargo feature is enabled (it always fails with this message). It is the runtime-less fallback so the macro produces a clear diagnostic instead of unresolved-symbol errors.","triggerScenarios":"Annotating `#[tokio::main]` on a function while `tokio` is a dependency without `features = [\"rt\"]` or `[\"rt-multi-thread\"]`.","commonSituations":"`tokio = { version = \"...\", default-features = false }` with only `macros` enabled; disabling default features then forgetting to add an `rt` feature; conditional feature flags that drop `rt` on some target.","solutions":["Enable a runtime feature in Cargo.toml: `tokio = { version = \"1\", features = [\"rt-multi-thread\", \"macros\"] }`.","For a single-threaded app, `features = [\"rt\", \"macros\"]` is sufficient.","Run `cargo tree -e features -p tokio` to confirm the `rt`/`rt-multi-thread` feature is actually active."],"exampleFix":"# before\ntokio = { version = \"1\", features = [\"macros\"] }\n\n# after\ntokio = { version = \"1\", features = [\"rt-multi-thread\", \"macros\"] }","handlingStrategy":"validation","validationCode":"// Verify in build.rs or a CI script that the rt feature is active:\n// `cargo tree -e features -p tokio | grep -E '\\b(rt|rt-multi-thread)\\b'`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always enable a runtime feature with `#[tokio::main]`: `rt` or `rt-multi-thread`.","After setting `default-features = false`, explicitly add back `rt`/`rt-multi-thread`.","Pin a workspace dependency template that includes `rt-multi-thread, macros`.","CI: assert required features with `cargo tree -e features`."],"tags":["rust","tokio","macros","features","compile-time","configuration"],"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"}