E0373: closure may outlive the current function Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function

A closure borrowing a local is passed somewhere that may outlive it (thread::spawn, tokio::spawn, returned closures).

Exact message you may see error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current functionclosure may outlive the current functionE0373 to force the closure to take ownership of `v` use the `move` keywordhelp: to force the closure to take ownership of
Seen on: Rust

Meaning

Use move so the closure takes ownership: thread::spawn(move || {...}). If you need the value afterwards, clone before moving, or share via Arc. For scoped use thread::scope(|s| ...) which allows borrowing.

Common causes

  • thread::spawn(|| use(v)) without move
  • tokio::spawn(async { ... }) borrowing locals
  • Returning a closure that borrows locals
  • Storing closures in structs
  • Callbacks outliving the function

⚡ Quick fix

  1. Add move to the closure
  2. Clone data first or wrap in Arc
  3. Use std::thread::scope to borrow

Detailed fix by platform

Rust

  1. `let v2 = v.clone(); thread::spawn(move
  2. println!("{v2:?}));`

How to diagnose

  1. Closure — Borrowing?
  2. Lifetime — Outlives the function?
  3. Fix — move/Arc/scope?

🔧 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 …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 …cargo: failed to select a version for the requirement — Cargo: error: failed to select a version for the requirement `serde = "^2.0"` — candidate versions found which didn't match: 1.0.197 (Rust)cargo: failed to sele…E0106: missing lifetime specifier — Rust: error[E0106]: missing lifetime specifier — this function's return type contains a borrowed value, but the signature does not say which one of `x`'s 2 lifetimes it is borrowed from (Rust)E0106: missing lifeti…E0505: cannot move out of value because it is borrowed — Rust: error[E0505]: cannot move out of `s` because it is borrowed (Rust)E0505: cannot move ou…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 …E0597: borrowed value does not live long enough — Rust: error[E0597]: `x` does not live long enough — borrowed value does not live long enough (Rust)E0597: borrowed value…feature edition2024 is required / Cargo.lock version too new — Cargo: error: failed to parse manifest — feature `edition2024` is required / lock file version 4 requires `-Znext-lockfile-bump` (Rust)feature edition2024 i…E0373: cl…

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.