E0014 — Unwrap of a None optional

An Optional value was force-unwrapped while holding None.


What triggers it

Code unwraps an Optional<T> (via ! or an unchecked try) at a point where the runtime value is None rather than Some(v). Unlike a checked match or if let, force-unwrap has no fallback path, so the runtime aborts.

Minimal example

fn find(int[] xs, int target) -> Optional<int> {
    return None;
}
fn main() {
    let v = find([1, 2, 3], 9)!;
}

Output:

scratch.rz:5:13: error[E0014]: unwrap of `None`
    let v = find([1, 2, 3], 9)!;
            ^^^^^^^^^^^^^^^^^^^

Fix

Handle the None case explicitly instead of force-unwrapping.

fn main() {
    let v = find([1, 2, 3], 9);
    if v is Some(x) {
        return x;
    }
    return 0;
}

Source

Emitted from the interpreter/VM’s Optional unwrap path in resilient/src/lib.rs.