E0507: cannot move out of a shared reference / index Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0507]: cannot move out of `self.name` which is behind a shared reference

You tried to take ownership of a value through a reference (or from a Vec/Option behind &).

Exact message you may see error[E0507]: cannot move out of `self.name` which is behind a shared referencecannot move out of index of `Vec<String>`cannot move out of borrowed contenterror[E0507]: cannot move out of a mutable referencemove occurs because has type which does not implement the `Copy` trait E0507
Seen on: Rust

Meaning

Clone (self.name.clone()), borrow (&self.name), use Option::take()/mem::replace/mem::take to move out safely, or change the function to take self by value. vec[i] can't move non-Copy elements; use &vec[i] or vec.remove(i).

Common causes

  • Moving a String/Vec field out of &self
  • Moving out of vec[i]
  • Option field behind &mut self moved without take()
  • Pattern matching moving out of a reference without ref/&
  • Returning an owned value from a borrowed field

⚡ Quick fix

  1. .clone() when cheap, or return &T
  2. self.field.take() / std::mem::take(&mut self.field)
  3. match &self.x { Some(v) => ... }

Detailed fix by platform

Rust

  1. let name = std::mem::take(&mut self.name);

How to diagnose

  1. Access — Through & or &mut?
  2. Type — Copy?
  3. Fix — take/clone/borrow?

🔧 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…E0382 — Rust: error[E0382]: borrow of moved value: `x` (Rust)E0382E0505: 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…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 …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…E0507: 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.