Rust: error[E0382]: borrow of moved value: `x`

A value was moved (ownership transferred) and then used again.

Exact message you may see borrow of moved valueuse of moved valuevalue moved here
Seen on: Rust

Meaning

Types like String and Vec move when passed by value or assigned. After a move, the original variable can’t be used. Borrow (&x), clone when you really need two owners, or restructure ownership.

Common causes

  • Passing a String/Vec by value to a function and using it after
  • Moving into a closure (move ||) or thread
  • Using a value after a for loop consumed it (for x in vec)

⚡ Quick fix

  1. Pass a reference (&value) instead
  2. .clone() if you need an independent copy
  3. Iterate by reference (for x in &vec)

Detailed fix by platform

Rust

  1. rust
    fn print_len(s: &String) { println!("{}", s.len()); }
    let name = String::from("Ada");
    print_len(&name);
    println!("{name}");   // still usable

How to diagnose

  1. Move — Line with "value moved here"
  2. Type — Implements Copy?

🔧 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):

E0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308E0499: 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 …E0502 — Rust: error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable (Rust)E0502E0505: 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…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…E0382

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.