Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0493: Linear value overwritten

CodeCategoryStability
E0493Struct and enumPermanent

Explanation

Assigning to a place normally drops its previous live value before storing the replacement. Rue cannot perform that implicit drop when the place carries a linear value, because linear values must be consumed explicitly. Reinitialization is legal only after the destination was provably moved out on every incoming path.

Likely cause

An assignment replaces an initialized linear local, field, or array element. Consume or move the old value first; if the place is moved out on every path, assigning a replacement then reinitializes empty storage instead of overwriting a live value.

Examples

Overwrite a live linear local

linear struct Token { value: i32 }
fn main() -> i32 {
    let mut token = Token { value: 1 };
    token = Token { value: 2 };
    @drop(token);
    0
}

Reinitialize after consuming the old value

linear struct Token { value: i32 }
fn consume(token: Token) { @drop(token); }
fn main() -> i32 {
    let mut token = Token { value: 1 };
    consume(token);
    token = Token { value: 2 };
    @drop(token);
    0
}

References