You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rust: a constructor that doesn't set every field calls Self::default(), which the struct never implements (E0599) #344
RustGenerator.WriteConstructorBody has two paths that call Self::default():
A constructor with no initialisers, on a struct whose fields declare no values, writes Self::default() (Coder/Languages/RustGenerator.cs:1641-1647).
Otherwise it appends struct-update syntax, ..Self::default(), for the fields not yet set (:1663-1668).
Neither works for a plain struct, because a plain struct derives nothing (:489-493; the derive logic at :665-676 applies only to records). Both outputs fail rustc.
Repro
A struct Point { x: int } with an empty constructor (Kind = Constructor) generates:
implPoint{pubfnnew() -> Self{Self::default()}}
rustc reports error[E0599]: no associated function or constant named 'default' found for struct 'Point'.
A class Counter { count: int; step: int = 1 } with an empty constructor generates Self { step: 1, ..Self::default() }, which fails with the same E0599.
RustGeneratorTests.Constructor_WithNoInitialisers_AsksForTheDefault (Coder.Test/Languages/RustGeneratorTests.cs:341-347) checks the generated text but never compiles it.
Suggested fix
Name every remaining field explicitly as field: Default::default(). That needs only the field types to implement Default, not the struct, and the generator already uses this spelling for an empty initialiser at :1655.
Alternatively, derive Default when every field type implements it, reusing the reachability walk the record derive already does.
Acceptance criteria
Both shapes above are added to RustGeneratedSourceCompilesTests, and they compile.
Related: #193 and #262 (both closed) introduced these code paths.
Activity
matt-edmondson commentedon Oct 29, 2026
Triage
Generated by Claude Code