E0505: cannot move out of value because it is borrowed Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0505]: cannot move out of `s` because it is borrowed

You moved a value while a reference to it was still in use.

Exact message you may see error[E0505]: cannot move out of `s` because it is borrowedcannot move out of because it is borrowedE0505 move out of value occurs here borrow later used heremove out of `x` occurs here borrow of `x` occurs here
Seen on: Rust

Meaning

A reference (&s) must not outlive a move of s. Use the reference before moving, clone (s.clone()), borrow instead of moving (takes(&s)), or restructure ownership so the borrow ends first.

Common causes

  • Passing s by value while &s is later used
  • Moving into a thread/closure while borrowed
  • Returning a value while keeping a reference
  • Pushing into a collection while holding a ref
  • Struct fields borrowed then moved

⚡ Quick fix

  1. Pass a reference (&s) or clone
  2. Finish using the borrow before the move
  3. Use Rc/Arc for shared ownership

Detailed fix by platform

Rust

  1. let r = &s; println!("{r}"); drop(s); // borrow ends before the move

How to diagnose

  1. Borrow — Still used after the move?
  2. Fix — Clone/borrow/reorder?

🔧 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 …E0373: closure may outlive the current function — Rust: error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function (Rust)E0373: closure may ou…E0382 — Rust: error[E0382]: borrow of moved value: `x` (Rust)E0382E0499: cannot borrow as mutable more than once at a time — Rust: error[E0499]: cannot borrow `v` as mutable more than once at a time (Rust)E0499: cannot borrow …E0507: cannot move out of a shared reference / index — Rust: error[E0507]: cannot move out of `self.name` which is behind a shared reference (Rust)E0507: cannot move ou…E0596: cannot borrow as mutable, as it is not declared as mutable — Rust: error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable (Rust)E0596: cannot borrow …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…E0505: ca…

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.