E0384: cannot assign twice to immutable variable Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0384]: cannot assign twice to immutable variable `x`

You reassigned a variable declared without mut.

Exact message you may see error[E0384]: cannot assign twice to immutable variable `x`cannot assign twice to immutable variableE0384 help: consider making this binding mutable: `mut x`cannot assign to `x`, as it is not declared as mutablecannot assign to immutable argument
Seen on: Rust

Meaning

Declare it let mut x = ... if reassignment is intended, or shadow it (let x = x + 1;) which creates a new binding. Function parameters are immutable too (mut param). For loops with counters use let mut.

Common causes

  • Missing mut on the variable
  • Reassigning function parameters
  • Loop counter immutable
  • Assigning in a closure without mut capture
  • Struct field assignment through immutable binding

⚡ Quick fix

  1. let mut x = 5;
  2. Shadow: let x = x + 1;
  3. fn f(mut x: i32) for parameters

Detailed fix by platform

Rust

  1. let mut count = 0; count += 1;

How to diagnose

  1. Binding — mut?
  2. Intent — Reassign or shadow?
  3. Param — mut?

🔧 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…E0381: used binding isn't initialized — Rust: error[E0381]: used binding `x` is possibly-uninitialized (Rust)E0381: used binding i…E0502 — Rust: error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable (Rust)E0502E0596: 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…E0384: 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.