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).