Rust: error[E0728]: `await` is only allowed inside `async` functions and blocks
You used .await in a normal (sync) function or closure.
error[E0728]: `await` is only allowed inside `async` functions and blocksonly allowed inside async functions and blocksE0728 this is not `async`error[E0728]: await is only allowed inside async functions Meaning
Make the function async fn (and .await its callers), use #[tokio::main] for main, wrap with async { ... } blocks, or block on the future with a runtime (tokio::runtime::Handle::current().block_on — never inside async). Closures need async move |..| or return an async block.
Common causes
.awaitin a non-async fnmainnot async.awaitinside a sync closure- Missing async runtime attribute
- Mixing sync libraries and async code
⚡ Quick fix
- Mark the function
async fn #[tokio::main] async fn main()- Use
block_ononly at the sync/async boundary
Detailed fix by platform
Rust
- rust
#[tokio::main] async fn main() { let body = reqwest::get(url).await?.text().await?; }
How to diagnose
- Function — async?
- main — Runtime attribute?
- Closure — async block?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Blocking waiting for file lock on package cache / build directory Cargo: Blocking waiting for file lock on package cache / on build directory
- 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
- 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/...`
Most viewed in Rust
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026