E0381: used binding isn't initialized Rust Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Rust: error[E0381]: used binding `x` is possibly-uninitialized

A variable might be read before every code path assigned it.

Exact message you may see error[E0381]: used binding `x` is possibly-uninitializedused binding `x` isn't initializedE0381 used binding is possibly-uninitializederror[E0381]: used binding is possibly-uninitializedbinding declared here but left uninitialized
Seen on: Rust

Meaning

Initialise at declaration, or ensure all branches assign (if/else both set it), or use Option<T> with None. Loops that may not execute leave it uninitialised. Rust requires definite assignment.

Common causes

  • Declared let x; and assigned in only some branches
  • Assignment inside a loop/conditional only
  • match arms not all assigning
  • Early return paths
  • Conditional compilation

⚡ Quick fix

  1. let x = if cond { 1 } else { 2 };
  2. Initialise with a default or Option<T>
  3. Ensure all branches assign before use

Detailed fix by platform

Rust

  1. let x = match cond { true => 1, false => 2 };

How to diagnose

  1. Paths — All assign?
  2. Default — Available?
  3. Option — Appropriate?

🔧 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…E0004: non-exhaustive patterns — Rust: error[E0004]: non-exhaustive patterns: `None` not covered (Rust)E0004: non-exhaustive…E0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308E0384: cannot assign twice to immutable variable — Rust: error[E0384]: cannot assign twice to immutable variable `x` (Rust)E0384: cannot assign …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…E0381: us…

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.