E0752: main function is not allowed to be async Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0752]: `main` function is not allowed to be `async`

async fn main() needs a runtime attribute (Tokio/async-std), the std main can't be async.

Exact message you may see error[E0752]: `main` function is not allowed to be `async``main` function is not allowed to be `async`error: the `#[tokio::main]` macro requires the `macros` featureE0752 `main` function is not allowed to be asynccannot find attribute `tokio::main`
Seen on: Rust

Meaning

Add #[tokio::main] (and tokio = { version = "1", features = ["full"] } in Cargo.toml) or #[async_std::main]. Or keep fn main() and build a runtime manually: tokio::runtime::Runtime::new()?.block_on(run()).

Common causes

  • async fn main() without a macro
  • Tokio missing from dependencies/features (macros, rt-multi-thread)
  • Wrong attribute path
  • Edition/proc-macro not resolved
  • Using futures without a runtime

⚡ Quick fix

  1. #[tokio::main] on async fn main()
  2. Cargo.toml: tokio = { version = "1", features = ["full"] }
  3. Or Runtime::new()?.block_on(...)

Detailed fix by platform

Rust

  1. cargo add tokio --features full

How to diagnose

  1. Attribute — tokio::main?
  2. Features — macros, rt?
  3. Runtime — Manual?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Blocking waiting for file lock on package cache / build directory — Cargo: Blocking waiting for file lock on package cache / on build directory (Rust)Blocking waiting for …Cannot start a runtime from within a runtime (Tokio) — Rust: thread 'main' panicked: Cannot start a runtime from within a runtime — a function like `block_on` tried to block a thread that drives async tasks (Rust)Cannot start a runtim…cargo: failed to get from registry (spurious network error) — Cargo: warning: spurious network error (2 tries remaining): [35] SSL connect error / error: failed to download from `https://index.crates.io/...` (Rust)cargo: failed to get …E0433: failed to resolve: use of undeclared type or module — Rust: error[E0433]: failed to resolve: use of undeclared type `HashMap` (Rust)E0433: failed to reso…E0521: borrowed data escapes outside of function — Rust: error[E0521]: borrowed data escapes outside of function — `data` escapes the function body here (tokio::spawn requires 'static) (Rust)E0521: borrowed data …E0728: await is only allowed inside async functions and blocks — Rust: error[E0728]: `await` is only allowed inside `async` functions and blocks (Rust)E0728: await is only …there is no reactor running, must be called from the context of a Tokio 1.x runtime — Rust: thread 'main' panicked: there is no reactor running, must be called from the context of a Tokio 1.x runtime (Rust)there is no reactor r…E0752: ma…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.