Pular para o conteúdo
TE128 · Tipos · error

Origem do spread precisa ser struct ou record

O spread final de um literal de struct (`Struct { ..origem }`) tem uma `origem` que não é struct nem record, então não há campos a espalhar.

Why this fires

A struct literal's trailing spread (Struct { ..source }) has a source that isn't a struct or record — there are no fields to spread in from it.

struct User { name: str, age: int }

fn f() -> User {
    return User { name: "Z", ..42 }
    //                        ^^ error[TE128]: spread source must be a struct or
    //                           record, got 'int'
}

Fix it

Spread from an actual struct/record value:

struct User { name: str, age: int }

fn f(u: User) -> User {
    return User { name: "Z", ..u }   // ok — u is a User
}

See also

  • TE107 — missing field in struct construction (fires when the spread source doesn't cover all remaining fields).
  • /docs/data-structures#structs — struct-literal spread (..expr).

Buscar no Zolo

9 resultados

en