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

E0429: Move out of borrow

CodeCategoryStability
E0429Struct and enumPermanent

Explanation

Code tries to move a non-Copy value out of storage held under a shared loan, such as a borrow parameter or an element borrowed by for. Neither the whole borrowed value nor a non-Copy field or element belongs to the current operation, so transferring its ownership would invalidate the loaned storage.

Likely cause

A borrowed value or one of its non-Copy projections was returned, stored in an owned aggregate, or passed to a by-value consumer. Read Copy data through the loan, pass the value onward as borrow, or change the API or iteration so ownership transfers explicitly.

Examples

Move a borrowed value into a consumer

struct Item { value: i32 }
fn consume(item: Item) -> i32 { item.value }
fn invalid(borrow item: Item) -> i32 { consume(item) }
fn main() -> i32 {
    let item = Item { value: 42 };
    invalid(borrow item)
}

Borrow the value in the nested call

struct Item { value: i32 }
fn read(borrow item: Item) -> i32 { item.value }
fn valid(borrow item: Item) -> i32 { read(borrow item) }
fn main() -> i32 {
    let item = Item { value: 42 };
    valid(borrow item)
}

References