Pular para o conteúdo
TE112 · Tipos · error

Campo embutido por `using` é ambíguo

Dois ou mais campos embutidos com `using` declaram um campo de mesmo nome, então um acesso `.campo` no struct externo não sabe de qual embed promovê-lo.

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

Veja também

Buscar no Zolo

9 resultados

en