E0437: Move out of inout
| Code | Category | Stability |
|---|---|---|
E0437 | Struct and enum | Permanent |
Explanation
A function tries to move a non-Copy value, or a non-Copy part of one, out of an inout parameter. The callee has exclusive mutable access to caller-owned storage but does not own that storage's value, so moving it would leave the caller with an invalid or partially moved value.
Likely cause
The parameter was returned, assigned to a new owner, or passed to a by-value parameter. Mutate or replace it in place, forward it to another inout parameter, borrow it, or read only Copy fields. Move-then-reinitialize is also rejected because Rue does not track reinitialization of inout parameters.
Examples
Move an inout value to a new owner
struct Item { value: i32 }
fn take(item: Item) -> i32 { item.value }
fn inspect(inout item: Item) -> i32 { take(item) }
fn main() -> i32 {
let mut item = Item { value: 42 };
inspect(inout item)
}
Read a Copy field without moving the inout value
struct Item { value: i32 }
fn inspect(inout item: Item) -> i32 { item.value }
fn main() -> i32 {
let mut item = Item { value: 42 };
inspect(inout item)
}