Skip to content
TE112 · Type · error

`using`-embedded field is ambiguous

Two or more `using`-embedded fields declare a field with the same name, so a `.field` access on the outer struct can't tell which embed to promote it from.

Why this fires

A struct has two or more using-embedded fields whose types declare a field with the same name, and a .field access on the outer struct can't tell which embed to promote it from.

struct A { x: int }
struct B { x: int }
struct P { using a: A, using b: B }

fn go(p: P) -> int {
    return p.x
    //       ^ error[TE112]: field 'x' is ambiguous between `using` embeds;
    //         qualify it, e.g. `<recv>.<embed>.x`
}

Both A and B embed a field named x, so p.x alone doesn't say which one is meant.

Fix it

Qualify the access through the embed you want:

fn go(p: P) -> int {
    return p.a.x            // ok — explicitly through embed `a`
}

See also

See also

Search Zolo

9 results

en