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

E0426: Inout exclusive access

CodeCategoryStability
E0426Struct and enumPermanent

Explanation

One call grants more than one exclusive inout access to the same root variable through its arguments, receiver, or accessor-rooted places. Rue grants exclusive access at root granularity, so even different fields or elements of one aggregate cannot be independently loaned by the same call.

Likely cause

Two exclusive accesses use the same variable directly or project from the same struct or array. Split the operation into separate calls, or place independently accessed values in distinct root variables.

Examples

Loan distinct fields of one root

struct Pair { left: i32, right: i32 }
fn swap(inout a: i32, inout b: i32) {
    let old = a;
    a = b;
    b = old;
}
fn main() -> i32 {
    let mut pair = Pair { left: 1, right: 2 };
    swap(inout pair.left, inout pair.right);
    pair.left
}

Loan distinct root variables

fn swap(inout a: i32, inout b: i32) {
    let old = a;
    a = b;
    b = old;
}
fn main() -> i32 {
    let mut left = 1;
    let mut right = 2;
    swap(inout left, inout right);
    left + right
}

References