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

E0480: Assign to partially moved array

CodeCategoryStability
E0480Struct and enumPermanent

Explanation

After a non-Copy array element is moved out, Rue tracks the array as partially moved. Assigning to an element, or through an element to one of its fields, cannot re-establish per-element ownership and is rejected even when the assignment targets the same constant index. Whole-array reinitialization restores ownership for an affine array; when the element type carries a linear value, it is legal only after every element has first been consumed.

Likely cause

Code moves an element from an array and later writes an element or nested field of that array. For an affine array, replace the whole array value instead. For an array carrying linear values, explicitly consume every remaining live element before whole-array reinitialization, or restructure the code so no element is moved before the write.

Examples

Write the element that was moved out

struct Item { value: i32 }
fn take(item: Item) -> i32 { item.value }
fn main() -> i32 {
    let mut items = [Item { value: 1 }, Item { value: 2 }];
    let first = take(items[0]);
    items[0] = Item { value: 9 };
    first
}

Reinitialize the whole array

struct Item { value: i32 }
fn take(item: Item) -> i32 { item.value }
fn main() -> i32 {
    let mut items = [Item { value: 1 }, Item { value: 2 }];
    let first = take(items[0]);
    items = [Item { value: 9 }, Item { value: 10 }];
    first + items[0].value
}

References